How to preserve apostrophe sign in a string in Matlab?
26 次查看(过去 30 天)
显示 更早的评论
I am facing a problem while working with a string which has two or more apostrophe ( ' ) signs. When I run a function on it, it automatically erase all apostrophe signs except one. Can you provide me any solution for this?
x = 'La drôle de tête du râteau est posée contre le mûr près de l''abîme'; %Input String
Output = 'La drole de tete du rateau est posee contre le mur près de l''abime' % What I need to get
Ignore the French accents. Everytime I run the code, only one apostrophe sign left in the string.
Thanks in advance!!
0 个评论
回答(1 个)
Star Strider
2021-5-24
Enclose the apostrophes in apostrophes —
x = 'La drôle de tête du râteau est posée contre le mûr près de l''''abîme';
sprintf('%s',x)
Alternatively —
x = 'La drôle de tête du râteau est posée contre le mûr près de l''abîme';
sprintf('%s',x)
To get a slightly different result.
.
2 个评论
Steven Lord
2021-5-24
Alternately create a string array instead of a char array.
s = "Here's how you include a single quote in a string"
c = 'Here''s how you include a single quote in a char'
s2 = sprintf("Two single quotes '' is no problem in a string")
Stephen23
2021-5-24
"Enclose the apostrophes in apostrophes"
They are escaped rather than enclosed:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!