使用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;
??? }