日期:2014-05-20  浏览次数:20637 次

使用splipt方法时遇到的一个问题
String   chjyfw= "第一类|宾馆;第一类|酒吧;第二类|理发店;第三类|舞厅;其它|卡拉OK; ";

Map   map   =   new   HashMap();
        if(chjyfw.contains( "; ")){
String   []strArr_big   =   chjyfw.split( "; ");

for(int   i=0;i <strArr_big.length;i++){

String   strArr_small[]   =   strArr_big[0].split( "| ");
String   temp   =   strArr_big[0];

strArr_small   =   temp.split( "| ");
map.put(strArr_small[0],   strArr_small[1]);
}
}

看看map里有什么内容,解释原因。

------解决方案--------------------
split的参数是正则表达式

完。
------解决方案--------------------
用 "\\| "原因如上楼
------解决方案--------------------
原因如楼上的楼上
------解决方案--------------------
str.split( "[;|] "))
------解决方案--------------------
使用正则表达式串[;]和[,]即可。split使用的正则表达式串。