0

输入:

MECR-tree obtained using \textbf{MCAR-Miner} with $S_{\mathrm{U}}  = data$ 25{\%} and $S_{\mathrm{L}}  = string$ 12.5{\%}

将其更改为标题大小写,但免除 $ 符号内的文本。

输出应该是:

Mecr-Tree Obtained Using \textbf{Mcar-Miner} With $S_{\mathrm{U}}  = data$ 25{\%} And $S_{\mathrm{L}}  = string$ 12.5{\%}
4

1 回答 1

1

这是一个假设$字符总是成对出现的示例:

sp = s.split('$')
for i, seg in enumerate(sp):
    if i % 2 == 0:
        sp[i] = seg.title()

print('$'.join(sp))

使用列表推导:

print(r'$'.join([seg.title() if not i % 2 else seg for i, seg in enumerate(s.split('$'))]))
于 2017-07-20T14:57:22.447 回答