How to display a long string in multiple lines?

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일

2 개 추천

PerLine = 80;
pattern = sprintf('.{1,%d}', PerLine);
str = regexp(C{n,1}, pattern, 'match');
fprintf('%s\n', str{:});

댓글 수: 2

Yes it worked very well, thank you!
giannit
giannit 2021년 3월 30일
Thank you i was looking for that!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2018년 9월 17일

댓글:

2021년 3월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by