Java-将两个字符串转换为单个字符串

时间:2013-03-27 20:21:25

标签: java string

我有两个字符串

String str1= "B0000001";
String str2= "Testing";

StringBuilder sb= new StringBuilder();
sb.append(str1)
sb.append("\\");
sb.append(str2);
return sb.toString();

我得到的结果是“B0000001”\“测试”

但我希望结果为“B0000001 \ Testing”

我怎样才能实现它?

1 个答案:

答案 0 :(得分:3)

  String str1 = "B0000001";
  String str2 = "Testing";
  StringBuilder sb = new StringBuilder();
  sb.append(str1);
  sb.append("\"\\\"");///////////(\")--->for (") and (\\) for(\) and (\")-->for (")
  sb.append(str2);
  System.out.println( sb.toString());

输出为: B0000001“\”测试

String str1= "B0000001"
String str2= "Testing"

StringBuilder sb= new StringBuilder();
sb.append(str1)
sb.append("\\");
sb.append(str2);
return sb.toString();

输出为: B0000001 \ Testing