我将在字符串中查找数字字符并将其替换为阿拉伯语版本。该代码是:
public static void main(String[] args) {
String pattern = "[0-9]+";
Pattern p = Pattern.compile(pattern);
String mainText = "34titi685dytti5685fjjfj8585443";
Matcher m = p.matcher(mainText);
int i = 0;
while (m.find()) {
System.out.println("Match number " + i);
String tmp = m.group();
char[] cTmp = tmp.toCharArray();
for (int j = 0; j < cTmp.length; j++) {
cTmp[j] = (char) ((int) cTmp[j] + 1584);
}
m.group().replaceFirst(tmp,new String(cTmp));
i++;
}
System.out.println(mainText);
}
但最后它会打印相同的字符串mainText
。我的代码有什么问题?