zoukankan      html  css  js  c++  java
  • java从字符串中提取数字

    转:

    java从字符串中提取数字

      1. // 判断一个字符串是否都为数字  
      2. public boolean isDigit(String strNum) {  
      3.     return strNum.matches("[0-9]{1,}");  
      4. }  
      5.   
      6. // 判断一个字符串是否都为数字  
      7. public boolean isDigit(String strNum) {  
      8.     Pattern pattern = Pattern.compile("[0-9]{1,}");  
      9.     Matcher matcher = pattern.matcher((CharSequence) strNum);  
      10.     return matcher.matches();  
      11. }  
      12.   
      13.    //截取数字  
      14.    public String getNumbers(String content) {  
      15.        Pattern pattern = Pattern.compile("\d+");  
      16.        Matcher matcher = pattern.matcher(content);  
      17.        while (matcher.find()) {  
      18.            return matcher.group(0);  
      19.        }  
      20.        return "";  
      21.    }  
      22.   
      23. // 截取非数字  
      24. public String splitNotNumber(String content) {  
      25.     Pattern pattern = Pattern.compile("\D+");  
      26.     Matcher matcher = pattern.matcher(content);  
      27.     while (matcher.find()) {  
      28.         return matcher.group(0);  
      29.     }  
      30.     return "";  

  • 相关阅读:
    recess----2.Controller里面取用request信息
    recess----1.第一个APP-helloRecess
    Introducing MVC
    IFA Basics
    Why do Antennas Radiate?
    [JSP]JSP 简介
    [Spring]04_最小化Spring XML配置
    [设计模式]创建型模式
    [设计模式]原型模式
    [设计模式]建造者模式
  • 原文地址:https://www.cnblogs.com/libin6505/p/13433429.html
Copyright © 2011-2022 走看看