如:“测试字符串-这个字符串后面有回车否,怎么去掉?
”;

解决方案 »

  1.   

            System.out.print("测试字符串-这个字符串后面有回车否,怎么去掉?\n".replaceAll("\n*$", ""));
            System.out.println("ok");
      

  2.   

    这样更好点
    System.out.print("测试字符串-这个字符串后面有回车否,怎么去掉?\n\r".replaceAll("[\r\n]*$", ""));
            System.out.println("ok");
      

  3.   


    public class Test {
    public static void main(String[] args) {
    String src = "测试字符串-这个字符串后面有回车否,怎么去掉?\r\n";
    System.out.println("-----------------");
    System.out.println(src);
    System.out.println("-----------------");
    System.out.println(src.trim());
    System.out.println("-----------------");
    }
    }输出:
    -----------------
    测试字符串-这个字符串后面有回车否,怎么去掉?���-----------------
    测试字符串-这个字符串后面有回车否,怎么去掉?���
    -----------------
      

  4.   

    "测试字符串-这个字符串后面有回车否,怎么去掉?\r\n".trim()即可
      

  5.   

    输入的文本如果保存在String类型的变量text中,那可以这样
    text = text.replaceAll("[\r\n]*", ""));不知道理解得对不对
      

  6.   


    兄台,,不是啊 !如下:
    源:String string  = "this is test-stri
    ng";
    目的:String string  = "this is test-string";
      

  7.   


    兄台,,不是啊 !如下:
    源:[/color]String string  = "this is test-stri
    ng";
    目的:[/color]String string  = "this is test-string";
      

  8.   

    兄台,,不是啊 !如下:
    源:String string  = "this is test-stri
    ng";
    目的:String string  = "this is test-string";
      

  9.   

    lz要
    什么意思啊?  
    这个?
    String string = "this is test-string";
    敲下回车
    String string = "this is test-stri"+
                      "ng";