필터 지우기
필터 지우기

Problem with a string .

조회 수: 4 (최근 30일)
Jonasz
Jonasz 2013년 9월 17일
Hello here is my string :
'abc "abc" '
I need to throw out single quotation mark and replace double quotation mark to single quotation mark so the output will be :
abc 'abc'
How to do it ?
Thanks a lot.

채택된 답변

Jan
Jan 2013년 9월 17일
What does "here is my string" exactly mean? Strings do not contain the surrounding quotes. They appear only, if e.g. a cell string is printed to the command window:
C = {'string'};
disp(C)
Therefore I assume this is enough:
S = 'abc "abc" ';
S = strrep(S, '"', char(39));
fprintf('%s\n', S);
I use char(39) because it looks less strange than '''', but both create exactly the same: one quote character.
  댓글 수: 2
Jonasz
Jonasz 2013년 9월 17일
I need to delete this quotes because I use later this into function find.
find(S)
when I use it the problem is that it doesn't work as it should. The function work fine when I put this statement without quotes.
Jan
Jan 2013년 9월 17일
@Jonasz: It is not clear, if your string is:
S = 'abc "abc" '
or
S = '''abc "abc" '''
Please clarify this at first.

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

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2013년 9월 17일
doc strrep
Here it is:
str = '''abc "abc" '''
str2 = strrep(strrep(str,'''',''),'"','''')

카테고리

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