一个字符串2边本身含有双引号,如何去掉?

解决方案 »

  1.   

    String newStr = oldStr.replaceAll("\"","\\\"");
      

  2.   

    String newStr = oldStr.replaceAll("\"","\\\"");2边的双引号去不掉啊
      

  3.   

    原来是要去掉啊.中间的去掉吗?
    String newStr = oldStr.replaceAll("\"","");  //这个是把所有的 " 都去掉.
      

  4.   

    //String str;
    if(str.indexOf("\"")==0) str = str.substring(1,str.length());   //去掉第一个 "
    if(str.lastIndexOf("\"")==(str.length()-1)) str = str.substring(0,str.length()-1);  //去掉最后一个 " 
      

  5.   

    package thread;import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class T { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    String s="\"aasd\"a\"";
    String result=null;
    Pattern p=Pattern.compile("(?m)^\"(.+)\"$");
    Matcher m=p.matcher(s);
    if(m.find()){
    result=m.group(1);
    }
    System.out.println(result);
    }}
    只去掉开头的
      

  6.   

    String newStr = oldStr.replaceAll("\"","");  这样是不行的,连内容也去了!!
      

  7.   

    replaceAll
    public String replaceAll(String regex,
                             String replacement)
    Replaces each substring of this string that matches the given regular expression with the given replacement. 
    An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression Pattern.compile(regex).matcher(str).replaceAll(repl)Parameters:
    regex - the regular expression to which this string is to be matched 
    Returns:
    The resulting String 
    Throws: 
    PatternSyntaxException - if the regular expression's syntax is invalid
    Since: 
    1.4 
    See Also:
    Pattern
      

  8.   

    如果只是头尾的“要去掉
    直接 str = str.substring(1,str.length()-1);
    不就完了
      

  9.   

    同上
    先判断 然后substring