How to preserve apostrophe sign in a string in Matlab?

조회 수: 25 (최근 30일)
Nafees Ul Haque Akhand
Nafees Ul Haque Akhand 2021년 5월 24일
댓글: Stephen23 2021년 5월 24일
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!!

답변 (1개)

Star Strider
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)
ans = 'La drôle de tête du râteau est posée contre le mûr près de l''abîme'
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)
ans = 'La drôle de tête du râteau est posée contre le mûr près de l'abîme'
To get a slightly different result.
.
  댓글 수: 2
Steven Lord
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"
s = "Here's how you include a single quote in a string"
c = 'Here''s how you include a single quote in a char'
c = 'Here's how you include a single quote in a char'
s2 = sprintf("Two single quotes '' is no problem in a string")
s2 = "Two single quotes '' is no problem in a string"
Stephen23
Stephen23 2021년 5월 24일
"Enclose the apostrophes in apostrophes"
They are escaped rather than enclosed:

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by