今天上午去面试时,是机试,有一道题是关于分隔字符串的,我感觉比较有意思,题是这样的:
        给一字符串:中国,澳州|加拿大/墨西哥 ,要求输出为去除分隔符的一个数组,即:中国 澳州 加拿大 墨西哥,当时偶因为身体不太舒服,这道题没做出来,晚上回家想,这个题还挺有意思,就换了种方式来解决,方案如下:
       public static String[] splitString(String str){
              String [] s = str.split(",");
              String [] t = new String[4];
              t[0] = s[0];
              s = s[1].split("\\|");
              t[1] = s[0];
              s = s[1].split("/"); 
              t[2] = s[0];
              t[3] = s[1];
  
              return t;
 }
         现在有点喜欢极限编程啦,这种感觉很nice!