1

This is my string:

String str = "CREATE TABLE `patiant` (  `ID` varchar(45) NOT NULL,  `PATIANT_NAME`...";

I tried using replace and replaceAll methods but didn't work.
Here you can see what I'v tried I don't know why it's not working:

  1. temp = str.replace("'","");
  2. temp = str.replaceAll("(^')","");

How to remove all quotes from the string?
Thanks

4

3 回答 3

2

您所有的引号都是重音符号(`),因此您替换了错误类型的引号。所以试试这个:

temp = str.replaceAll("`","");
于 2013-06-01T22:04:11.050 回答
1

输入String包含反引号而不是单引号,因此需要替换这些而不是后者:

任何一个

temp = str.replace("`", "");

或者

temp = str.replaceAll("`", "");

将正确执行更换

于 2013-06-01T22:04:01.067 回答
0

这里的代码,所以你现在可以证明是正确的:


public class TestMain {

public TestMain() {
    // TODO Auto-generated constructor stub
}


public static void main(String[] args) {

    String str = "CREATE TABLE `patiant` (  `ID` varchar(45) NOT NULL,  `PATIANT_NAME`...";
    String new_string_remplace = str.replaceAll("`",""); 
    System.out.println(new_string_remplace);
    //RESULT: CREATE TABLE patiant (  ID varchar(45) NOT NULL,  PATIANT_NAME...

}

}

注意:替换 String java.lang.String.replaceAll(String regex, String replacement)。

用给定的替换替换此字符串中与给定正则表达式匹配的每个子字符串。

调用 str.replaceAll(regex, repl) 形式的此方法会产生与表达式完全相同的结果

于 2013-06-02T17:29:55.860 回答