Creating a string scalar with line continuation

11 vues (au cours des 30 derniers jours)
Greg
Greg le 20 Jan 2018
Commenté : Greg le 20 Jan 2018
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?

Réponse acceptée

Walter Roberson
Walter Roberson le 20 Jan 2018
Replace the comma with a +
  3 commentaires
Walter Roberson
Walter Roberson le 20 Jan 2018
Correct.
Greg
Greg le 20 Jan 2018
Ahh, thank you! Forgot about the + operator. This is why we ask questions on the forum. :-D

Connectez-vous pour commenter.

Plus de réponses (1)

ES
ES le 20 Jan 2018
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
  1 commentaire
Greg
Greg le 20 Jan 2018
This is a char array, not string.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by