【发布时间】:2012-12-13 10:22:13
【问题描述】:
如何替换字符串中的\0(NUL)?
String b = "2012yyyy06mm"; // sth what i want
String c = "2\0\0\0012yyyy06mm";
String d = c.replaceAll("\\\\0", ""); // not work
String e = d.replace("\0", ""); // er, the same
System.out.println(c+"\n"+d+"\n"+e);
String bb = "2012yyyy06mm";
System.out.println(b.length() + " > " +bb.length());
以上代码将在控制台打印 12 > 11。糟糕,发生了什么事?
String e = c.replace("\0", "");
System.out.println(e); // just print 2(a bad character)2yyyy06mm
【问题讨论】:
标签: java string null-terminated