Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用replace从字符串中删除单引号_Java_Android_Replace - Fatal编程技术网

Java 如何使用replace从字符串中删除单引号

Java 如何使用replace从字符串中删除单引号,java,android,replace,Java,Android,Replace,如何替换下面的字符串 String test = "This is my Test's cases"; 现在我用空格替换“'”,意思是“这是我的测试用例” 我试过: 。。。但我没有得到任何要求的结果 测试代码: String test = "The First American's style"; System.out.println("old text::"+test); test = test.replaceAll("'","\\'"); System.out.println

如何替换下面的字符串

String test =  "This is my Test's cases";
现在我用空格替换“'”,意思是“这是我的测试用例” 我试过:

。。。但我没有得到任何要求的结果

测试代码:

String test = "The First American's style";
System.out.println("old text::"+test);      
test = test.replaceAll("'","\\'");
System.out.println("new text::"+test);

当您想用空格替换
时,为什么不这样做呢

test = test.replaceAll("'", " ");

这很好:

    String test = "The First American's style";
    System.out.println("old text::"+test);      
    test = test.replaceAll("'","");
    System.out.println("new text::"+test);
输出:

old text::The First American's style
new text::The First Americans style

使用ASCII、unicode值替换单引号

    test = test.replaceAll((char)145,"");
otherwise  
     test = test.replaceAll(\u0091,"");
更多信息


完成享受…

这根本不是真的,只是运行它并获得
新文本::结果是第一个美国的s样式
。你认为用
文本s
替换
文本
有什么意义吗?@raina77ow是的,因为当OP成功地将一个特定字符替换为另一个字符时,他可以自由使用任何角色。唉。。。在完美的世界里,你的方法也是完美的。可悲的是,事实并非如此。OP确实提到他已经“尝试”使用
replaceAll(“”,“)
(这应该适合他)。你的解决方案很可能只是工具箱中的另一个工具,对他来说毫无意义。我认为,正确的方法是首先理解OP方法的错误。OP尝试了这个解决方案,但犯了一个错误。OP没有留下空间,他/她的方法是
replaceAll(“,”)
,OP应该使用的是
replaceAll(“,”)
(参见replaceAll的第二个参数).您的问题标题与您的示例相矛盾。您不必在字符串文字中转义撇号。(单个)空格不是没有字符的空字符串(也称为“空字符串”)。您的问题说的是“空格”,这并不意味着“。这个问题似乎离题了,因为问题本身有答案。我真的觉得问题被打破了,正如OP提到的,他确实尝试了
替换.All(“,”)
。不过,你是唯一一个试图理解OP真正需要什么(而不是他应得什么)的人,因此我给你+1。)
    String test = "The First American's style";
    System.out.println("old text::"+test);      
    test = test.replaceAll("'","");
    System.out.println("new text::"+test);
old text::The First American's style
new text::The First Americans style
StringBuilder sb = new StringBuilder("Hey replace string's name.");
System.out.println("Old String::"+sb.toString());      
System.out.println("New String::"+sb.toString().replaceAll("'", ""));
    test = test.replaceAll((char)145,"");
otherwise  
     test = test.replaceAll(\u0091,"");