How to find "Enter" between the lines of a text and replace with "Alt+Enter"?

32 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 20 Oct 2012
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)) = '';

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!