Azzera filtri
Azzera filtri

How can I put single quotes inside single quotes?

29 visualizzazioni (ultimi 30 giorni)
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 Commento
Stephen23
Stephen23 il 8 Dic 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."

Accedi per commentare.

Risposta accettata

DGM
DGM il 8 Dic 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' '!' '@' '"' '''

Più risposte (0)

Categorie

Scopri di più su Entering Commands in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by