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