奇怪的问题。我有一根这样的绳子:
{john=1054.39, bob=345.67, fred=12.45}每次在字符串中看到等号时,我都想在字符串后面加一个$。在Groovy中这样做的最佳方法是什么,并将代码的数量保持在最低限度?在此之前,非常感谢您。
发布于 2018-07-10 14:11:30
您可以将所有=\d+替换为=\$$1
def str = '{john=1054.39, bob=345.67, fred=12.45}'
def modified = str.replaceAll('=(\\d+)', '=\\$$1')
assert modified == '{john=$1054.39, bob=$345.67, fred=$12.45}'https://stackoverflow.com/questions/51267278
复制相似问题