필터 지우기
필터 지우기

Creating a string scalar with line continuation

조회 수: 7 (최근 30일)
Greg
Greg 2018년 1월 20일
댓글: Greg 2018년 1월 20일
I'm passionately against breaking the 80'ish character width limit in code files. Therefore, I use line continuation ellipses heavily. I recently realized I can't find a (nice/non-redundant) way to create a string scalar with a line continuation.
myStr = ["Hello this is an extremely long sentence that would go ", ...
"beyond my 80-character limit."];
Results in a 1x2 string array. Obviously,
myStr = string(['Hello this is an extremely long sentence that ', ...
'would go beyond my 80-character limit.'])
gives me the desired output, but it feels redundant creating a char array then converting to a string array.
Any thoughts?

채택된 답변

Walter Roberson
Walter Roberson 2018년 1월 20일
Replace the comma with a +
  댓글 수: 3
Walter Roberson
Walter Roberson 2018년 1월 20일
Correct.
Greg
Greg 2018년 1월 20일
Ahh, thank you! Forgot about the + operator. This is why we ask questions on the forum. :-D

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

추가 답변 (1개)

ES
ES 2018년 1월 20일
myStr = ['Hello this is an extremely long sentence that would go ', ...
'beyond my 80-character limit.'];
disp(myStr)
whos myStr
Name Size Bytes Class Attributes
myStr 1x84 168 char

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by