代码改变世界

java中的竖线分割

2019-04-24 17:43  雄风狂飙  阅读(470)  评论(0)    收藏  举报

错误代码:

String tag = (Pattern.compile("|").split(areas[i]))[0];
这样分割 01|北京的结果是 0 、1、北、京

正确代码:

String tag = (Pattern.compile("\\|").split(areas[i]))[0];
这样分割 01|北京的结果是   01 、北京