cloudviz
cloudviz

Reputation: 1001

Sprintf Matlab with Apostrophe

I have a string listed below with apostrophe.

stringVar = '''L''hopital''s rule''' 

when I do sprintf i.e. sprintf(stringVar) it prints this 'L'hopital's rule'.

Now, what I would like to do is do an sprintf so that when I print it it will display as

'L''hopital''s rule'

Now I know I can easily do this '''L''''hopital''''s rule''' but would prefer to do it programatically. What's the best/correct way of approaching this problem. Note: I will need to handle many of these e.g. '''L''Environment'''.

Upvotes: 5

Views: 482

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112749

ind = regexp(stringVar, '\w''\w') + 1; %// detect quotes between word characters
stringVarRep = stringVar(sort([1:numel(stringVar) ind])); %// repeat those quotes

Upvotes: 3

Related Questions