How to erase newline character from string?
273 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Caglar
am 12 Nov. 2018
Bearbeitet: Alexander
am 18 Jun. 2024
Hello,
I am reading an xml file that contains new line (enter) character. How do I detect and erase it?
text=a.Olay(1)
text =
"YBasla
"
As you can see there is a new line character at the end of the string. Erase could not delete it this way:
erase(text,'↵')
ans =
"YBasla
"
Note that the string looks like this in a table
a =
6×5 table
(...) Olay (...) (...) (...)
_________________ ____________________________ ______________________ _________ __________
(...) "YBasla↵" (...) (...) (...)
I uploaded table and the text variable so that you can play with them.
2 Kommentare
Walter Roberson
am 12 Nov. 2018
erase(text,char(10))
Question though: is it possible that there are carriage returns as well as newline?
Akzeptierte Antwort
Stephen23
am 12 Nov. 2018
strtrim(text)
3 Kommentare
Donavan Haidinger
am 8 Feb. 2021
When working with the replace function, you might need to use char(10) or newline rather than '\n+'
Example:
table.fieldname = replace(table.fieldname,char(10),' ')
or
table.fieldname = replace(table.fieldname,newline,' ')
Both answers yield the same result
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!