How to display a long string in multiple lines?

조회 수: 11 (최근 30일)
Jing Ci Neo
Jing Ci Neo 2018년 9월 17일
댓글: giannit 2021년 3월 30일
I have a cell called C containing many strings, of which some are very long and it's hard to view in one line. I want to be able to call these strings and print them but in multiple lines: str=C{n,1}; fprintf('%s\n',str)
How I would be able to do that? Any help would be greatly appreciated.

채택된 답변

Walter Roberson
Walter Roberson 2018년 9월 17일
PerLine = 80;
pattern = sprintf('.{1,%d}', PerLine);
str = regexp(C{n,1}, pattern, 'match');
fprintf('%s\n', str{:});
  댓글 수: 2
Jing Ci Neo
Jing Ci Neo 2018년 9월 20일
Yes it worked very well, thank you!
giannit
giannit 2021년 3월 30일
Thank you i was looking for that!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by