I tried to replace "-" character in a Java String but is doesn't work :
str.replace("\u2014", "");
Could you help me ?
I tried to replace "-" character in a Java String but is doesn't work :
str.replace("\u2014", "");
Could you help me ?
String is Immutable in Java. You have to reassign it to get the result back:
String str ="your string with dashesh";
str= str.replace("\u2014", "");
See the API for details.
this simply works..
String str = "String-with-dash-";
str=str.replace("-", "");
System.out.println(str);
output - Stringwithdash
It's quite easy. You can use an Apache library, that will be useful while you develop an application. This is apache-commons-lang. You can do the following:
public class Main {
public static void main(String[] args) {
String test = "Dash - string";
String withoutDash = StringUtils.replace(test, "-", "");
System.out.println(withoutDash);
}
}