如何从字符串中移除特定字符。我有一个名为testingarray的ArrayList数组。
String line=testingarray.get(index).toString();
我希望可以从一行文字中删除特定的字符。
我有一个Unicode数组。
int uniCode[]={1611,1614,1615,1616,1617,1618};
我想删除那些具有这些Unicode的字符。
使用:
NewString = OldString.replaceAll("char", "");
在你的注释中提供的示例中使用:
NewString = OldString.replaceAll("d", "");
如需删除阿拉伯字符,请参见以下链接
String line = "foo";
line = line.replace("f", "");
System.out.println(line);
输出
oo
String line=testingarray.get(index).toString();
String cleanLine = line.replace("H", "");
更新(编辑后): 假设您已经有一个整数数组,其中包含要删除的Unicode字符(我假设这些整数是Unicode字符的十进制值):
String line=testingarray.get(index).toString();
int uniCodes[] = {1611,1614,1615,1616,1617,1618};
StringBuilder regexPattern = new StringBuilder("[");
for (int uniCode : uniCodes) {
regexPattern.append((char) uniCode);
}
regexPattern.append("]");
String result = line.replaceAll(regexPattern.toString(), "");
String result = yourString.replaceAll("your_character","");
例子:
String line=testingarray.get(index).toString();
String result = line.replaceAll("[-+.^:,]","");
d
字符? - Amulya Khare