【发布时间】:2017-05-12 20:41:31
【问题描述】:
我试图找到一种替换字符串中每个$# 的方法,其中$ 是文字字符'$',# 是一个数字(1 个或多个数字),并且将$# 替换为数组中# 位置处的字符串值。
这里有一些例子:
- 输入 1(字符串):
hello $2输入 2(数组)dave richard danny结果:hello richard
- 输入 1(字符串):
hi $4输入 2(数组)morgan ryan matthew nikoli结果:hi nikoli
PS:我刚从 C# 转回 Java,所以我忘记了很多东西(除非是语法之类的基础知识)
当前代码:
public static String parse(String command, String[] args) {
String substituted = "";
substituted = command;
return substituted;
}
我正在寻找一个可以用数组中的字符串替换表达式的函数。
【问题讨论】:
-
请分享代码,让我们知道您遇到的问题。
-
@WiktorStribiżew 我编辑了
-
@KenWhite 我编辑了
标签: java regex substitution