How can I put single quotes inside single quotes?

21 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2022-12-8
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."

请先登录,再进行评论。

采纳的回答

DGM
DGM 2022-12-8
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' '!' '@' '"' '''

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by