0
我有以下字符串:如何用Java中的参数替换所有出现的子字符串?
"useless text $TABLE[1]$ other useless text $TABLE[2]$ useless text..."
我想替换子串 “$ TABLE [X] $” 的东西的出现,如 “<表ID = 'X'>”。所以我需要从字符串中取回id并插入替换字符串中,并且这是针对所有事件的。
事情是这样的:
text = text.replace("$TABLE_[x]$", "<table id='x'>");
如果你想要全部替换,为什么不使用['replaceAll()'](https://www.tutorialspoint.com/java/java_string_replaceall.htm)? – progyammer