Refer to the character ' in a string

조회 수: 5 (최근 30일)
Edward
Edward 2013년 3월 31일
댓글: Steven Lord 2023년 1월 25일
Hi, i'm trying to write an algorithm to remove the character ' from a string, say for example: string='you're';
where I want to remove the ' to make the string 'youre' I get errors when I try to refer to a character as ''' though,
is there something I'm missing?
  댓글 수: 2
Stephen23
Stephen23 2023년 1월 25일
strrep('you''re','''','')
ans = 'youre'
Steven Lord
Steven Lord 2023년 1월 25일
This wasn't an option when the question was originally asked, but if you're using string arrays you don't need to double up the single quotes.
s = "you're"
s = "you're"
t1 = strrep(s, "'", "")
t1 = "youre"
t2 = erase(s, "'")
t2 = "youre"
t3 = replace(s, "'", "")
t3 = "youre"

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

답변 (1개)

Walter Roberson
Walter Roberson 2013년 3월 31일
string(string == '''') = '';
  댓글 수: 3
Image Analyst
Image Analyst 2013년 3월 31일
편집: Image Analyst 2013년 3월 31일
Why do it that way, which is dependent on the apostrophe being in the 4th position rather than the more general way Walter suggested? Heck if you're going to assume that, then you might as well do
a(4) = [];
or
a = [a(1:3), a(5:end)];
Perhaps what you were trying to do is this:
apostrophe = ''''
a= ['you', apostrophe, 're']
quoteLocation = strfind(a, apostrophe)
apostrophe =
'
a =
you're
quoteLocation =
4
Walter Roberson
Walter Roberson 2013년 3월 31일
strcmp('''', a)

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by