How to find "Enter" between the lines of a text and replace with "Alt+Enter"?
조회 수: 21 (최근 30일)
이전 댓글 표시
Hello everyone.
I have a text file like below:
"
I am good.
how are you?
are you there?
ok
that's all
"
the text contains so many lines. I want to remove the Enter between the lines. I know this command:
strrep(str,'','');
but with this I can not replace something with enter!
Additionally, I need to replace Enter with "alt+enter" character. alt+ Enter is the character which is not affected in text in notepad and you see the all the sentences in a line, but separate lines in word or notepad ++
here is this character between ""
"
"
attention that this is not Enter. this is another character!!
hope that you get the point.
thanks
댓글 수: 0
채택된 답변
Walter Roberson
2012년 10월 20일
s = fileread('YourFileName.txt');
s(s == char(10)) = ''; %10 is control-J, newline
Caution: you might have carriage return (13) as well as newline.
Looking around, I find vague hints that what you are referring to as alt-enter is implemented as newline, char(10). notepad required carriage-return / newline pairs to recognize end-of-line, but word and notepad++ can be set to recognize linefeed alone. In such a situation it would be sufficient to delete the carriage returns
s(s == char(13)) = '';
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!