今天要用String.split一個字符串2006-05-24|xxxx|xxx, 很自然地就用split("|"), 結果出來的String[]是這樣:
?????? String[0]=2
?????? String[1]=0
???????????? .
???????????? .
???????????? .
怎么會這樣?Google了一下,原來split的參數是regrex(正則表達式),一些特殊字符要用\來轉義,上面的正確寫法為:split("\\|")。
參看:
http://bbs.java.ccidnet.com/simple/index.php?t20665.html