finding carriage returns (i.e. \n) in a text file

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

 채택된 답변

Star Strider
Star Strider 2016년 1월 19일

3 개 추천

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.

추가 답변 (3개)

Walter Roberson
Walter Roberson 2016년 1월 19일

5 개 추천

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]))
Will Kinsman
Will Kinsman 2016년 1월 19일

0 개 추천

thank you so much. nailed it. Nothing better than the matlab forums.

댓글 수: 1

My pleasure!
They’re fun for me — I probably learn as much as I contribute.

댓글을 달려면 로그인하십시오.

Lamin Moore
Lamin Moore 2019년 3월 31일

0 개 추천

function res = capitalizeVowels(myWord)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2016년 1월 19일

답변:

2019년 3월 31일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by