亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Java用正則對字符串進(jìn)行處理并判斷是否能轉(zhuǎn)為數(shù)字

 更新時(shí)間:2018年06月01日 11:54:40   作者:連接數(shù)據(jù)庫  
這篇文章主要介紹了Java用正則對字符串進(jìn)行處理并判斷是否能轉(zhuǎn)為數(shù)字的實(shí)例代碼,代碼很簡單,需要的朋友可以參考下

代碼如下所示:

package java_test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * @author: gznc_pcc
 * @date:2018年6月1日 10:50:38
 * @version :
 * 
 */
class Main 
{
  public static void main(String[] args) {
    String lineString = "[\"1\"]";
    String line = "[\"on\",\"1\",\"5\",\"8\",\"10\"]";
    lineString = line.replaceAll("[\"\\[\\]]", "");//用""替換" [ ]
    String[] word = lineString.split(","); //以,切割
    System.out.println(lineString);
    for(int i=0;i<word.length;i++){
      Pattern pattern = Pattern.compile("[0-9]*"); //正則,匹配數(shù)字
      Matcher matcher = pattern.matcher(word[i]); 
      if(matcher.matches()){
        System.out.println("1:可以轉(zhuǎn)換");
        System.out.println(Integer.parseInt(word[i]));
      }
      else {
        System.out.println("2:不能轉(zhuǎn)換");
        System.out.println(word[i]);
      }
    }
  }
}

總結(jié)

以上所述是小編給大家介紹的Java用正則對字符串進(jìn)行處理并判斷是否能轉(zhuǎn)為數(shù)字,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論