Remove specific char from String [closed]

▼魔方 西西 提交于 2019-12-03 05:04:01
Shayan Pourvatan

use :

NewString = OldString.replaceAll("char", "");

in your Example in comment use:

NewString = OldString.replaceAll("d", "");

for removing Arabic character please see following link

how could i remove arabic punctuation form a String in java

removing characters of a specific unicode range from a string

you can replace character using replace method in string.

String line = "foo";
line = line.replace("f", "");
System.out.println(line);

output

oo

If it's a single char, there is no need to use replaceAll, which uses a regular expression. Assuming "H is the character you want to replace":

String line=testingarray.get(index).toString();
String cleanLine = line.replace("H", "");

update (after edit): since you already have an int array of unicodes you want to remove (i'm assuming the Integers are decimal value of the unicodes):

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(), "");

Try this,

String result = yourString.replaceAll("your_character","");

Example:

String line=testingarray.get(index).toString();
String result = line.replaceAll("[-+.^:,]","");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!