フィルターのクリア

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

21 ビュー (過去 30 日間)
Sonima
Sonima 2012 年 10 月 20 日
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

採用された回答

Walter Roberson
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 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by