How to erase newline character from string?
조회 수: 262 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2018년 11월 12일
erase(text,char(10))
Question though: is it possible that there are carriage returns as well as newline?
채택된 답변
Stephen23
2018년 11월 12일
strtrim(text)
댓글 수: 3
Donavan Haidinger
2021년 2월 8일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!