首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

使用String.split方法时要注意的有关问题

2012-10-30 
使用String.split方法时要注意的问题在使用String.split方法分隔字符串时,分隔符如果用到一些特殊字符,可

使用String.split方法时要注意的问题

在使用String.split方法分隔字符串时,分隔符如果用到一些特殊字符,可能会得不到我们预期的结果。

因此要在特殊字符前加\\

public String getUserAccount()
??? {
??????? String[] temp1 = userAccount.split("\\(");
??????? String[] temp2 = temp1[1].split("\\)");
??????? return temp2[0];
??? }

?

该方法也可以如下实现:

public String getUserAccount()
??? {
??????? String temp1 = userAccount.substring(userAccount.indexOf("(") + 1,
??????????????? userAccount.length() - 1);
??????? return temp1;
??? }

热点排行