9
如何在字符串中替換\ 0(NUL)?Java中的特殊字符 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
嗨,請幫忙。 String c =「2 \ 0 \ 0 \ 0012yyyy06mm」; \t \t String e = c.replace(「\ 0」,「」); \t \t System.out.println(e); \t \t \t \t //只是打印22yyyy06mm – user1900556
@ user1900556是的,因爲仍然嵌入其中的'\ 001'(在兩個「2」之間)是不可見的。整個觀點是,你所擁有的字符串「c」並不包含你認爲它所做的事情。 – Alnitak
有沒有辦法?該怎麼辦呢? – user1900556