finding carriage returns (i.e. \n) in a text file
119 次查看(过去 30 天)
显示 更早的评论
Hi all, I have a text file with carriage returns in it, and am trying to test if an index is a carriage return but have been unsuccessful. For simplicity, lets say that the text file only uses \r as a carriage return. I understand that isstrprop(text(index),'wspace') can identify if it is a space OR a carriage return, but I want to check only to see if it is a carriage return.
Any advice? Let me know if I can be any clearer here.
Thank you so much in advance, William
0 个评论
采纳的回答
Star Strider
2016-1-19
See if this does what you want:
Q = sprintf('This is a string \r with a newline character.\r');
NL = regexp(Q, '[\r]');
The ‘NL’ variable contains the indices of the occurrences of '\r' in the string.
0 个评论
更多回答(3 个)
Walter Roberson
2016-1-19
YourString == sprintf('\r')
or
YourString == char(13)
Note: char(13) is \r the carriage return. Your description uses the word carriage return but uses \n which is newline, char(10) . You need to decide which you are looking for. If you are looking for either, then
ismember(YourString, char([10 13]))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!