How can I put single quotes inside single quotes?

50 visualizaciones (últimos 30 días)
Daniel
Daniel el 8 de Dic. de 2022
Comentada: Daniel el 8 de Dic. de 2022
vector = ['a', 'b', 'c','d', '1', '2', '3', '!', '@', ' " ', ''' ];
in the above code segment the vector contain different elements but the last element which is single quote is not placed properly. so, how can i put it correctly?
  1 comentario
Stephen23
Stephen23 el 8 de Dic. de 2022
Square brackets are a concatenation operator, so this code:
V1 = ['a', 'b', 'c', 'd', '1', '2', '3', '!', '@', '"', '''' ]
is exactly equivalent to (but a pointlessly long and complex way of) simply writing this:
V2 = 'abcd123!@"'''
How to escape single quotes in character vectors is explained in the MATLAB documentation:
"If the text includes single quotes, use two single quotes within the definition."

Iniciar sesión para comentar.

Respuesta aceptada

DGM
DGM el 8 de Dic. de 2022
You can escape single quotes with another single quote. For sake of clarity, I'm going to transpose the output.
vector = ['a', 'b', 'c','d', '1', '2', '3', '!', '@', '"', '''' ].'
vector = 11×1 char array
'a' 'b' 'c' 'd' '1' '2' '3' '!' '@' '"' '''

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by