Effacer les filtres
Effacer les filtres

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

21 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Walter Roberson
Walter Roberson le 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)) = '';

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by