Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sprintf Matlab with Apostrophe

Tags:

matlab

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'''.

like image 474
cloudviz Avatar asked Oct 21 '22 12:10

cloudviz


1 Answers

ind = regexp(stringVar, '\w''\w') + 1; %// detect quotes between word characters
stringVarRep = stringVar(sort([1:numel(stringVar) ind])); %// repeat those quotes
like image 151
Luis Mendo Avatar answered Nov 04 '22 00:11

Luis Mendo