Creating a string scalar with line continuation

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?

 Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de En. de 2018

1 voto

Replace the comma with a +

3 comentarios

Stephen23
Stephen23 el 20 de En. de 2018
Editada: Stephen23 el 20 de En. de 2018
+1 Surely the square brackets are not required?:
myStr = "Hello this is an extremely long sentence that would go " + ...
"beyond my 80-character limit."
Correct.
Greg
Greg el 20 de En. de 2018
Ahh, thank you! Forgot about the + operator. This is why we ask questions on the forum. :-D

Iniciar sesión para comentar.

Más respuestas (1)

ES
ES el 20 de En. de 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

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Preguntada:

el 20 de En. de 2018

Comentada:

el 20 de En. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by