別忘了轉(zhuǎn)義\\
今天要用String.split一個(gè)字符串2006-05-24|xxxx|xxx, 很自然地就用split("|"), 結(jié)果出來(lái)的String[]是這樣:
?????? String[0]=2
?????? String[1]=0
???????????? .
???????????? .
???????????? .
怎么會(huì)這樣?Google了一下,原來(lái)split的參數(shù)是regrex(正則表達(dá)式),一些特殊字符要用\來(lái)轉(zhuǎn)義,上面的正確寫(xiě)法為:split("\\|")。
參看:http://bbs.java.ccidnet.com/simple/index.php?t20665.html
?????? String[0]=2
?????? String[1]=0
???????????? .
???????????? .
???????????? .
怎么會(huì)這樣?Google了一下,原來(lái)split的參數(shù)是regrex(正則表達(dá)式),一些特殊字符要用\來(lái)轉(zhuǎn)義,上面的正確寫(xiě)法為:split("\\|")。
參看:http://bbs.java.ccidnet.com/simple/index.php?t20665.html
posted on 2006-05-30 11:22 陳曉 閱讀(1067) 評(píng)論(4) 編輯 收藏