我在下面列出了一个带撇号的字符串。
stringVar = '''L''hopital''s rule'''
当我执行 sprintf 即 sprintf(stringVar) 时,它会打印此“L'hopital's rule”。
现在,我想做的是执行 sprintf,以便在打印时显示为
'L''hopital''s rule'
现在我知道我可以轻松地做到这一点 '''L''''hopital''''s rule'''
但我更愿意以编程方式进行。解决此问题的最佳/正确方法是什么。注意:我将需要处理其中的许多,例如'''L''环境'''。
最佳答案
ind = regexp(stringVar, '\w''\w') + 1; %// detect quotes between word characters
stringVarRep = stringVar(sort([1:numel(stringVar) ind])); %// repeat those quotes
关于matlab - 带有撇号的 Sprintf Matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22458151/