Problem with a string .

1 view (last 30 days)
Jonasz on 17 Sep 2013
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.

Accepted Answer

Jan on 17 Sep 2013
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'};
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.
Jan on 17 Sep 2013
@Jonasz: It is not clear, if your string is:
S = 'abc "abc" '
S = '''abc "abc" '''
Please clarify this at first.

Sign in to comment.

More Answers (1)

Sean de Wolski
Sean de Wolski on 17 Sep 2013
doc strrep
Here it is:
str = '''abc "abc" '''
str2 = strrep(strrep(str,'''',''),'"','''')


Find more on Characters and Strings in Help Center and File Exchange



Community Treasure Hunt

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

Start Hunting!