java 字符串中是否有数字

http://www.cnblogs.com/zhangj95/p/4198822.html

http://www.cnblogs.com/sunzn/archive/2013/07/12/3186518.html

参考:

 1 package cn.sunzn.demo;
 2
 3 import java.util.regex.Matcher;
 4 import java.util.regex.Pattern;
 5
 6 public class Demo {
 7     public static void main(String[] args) {
 8         System.out.println(isContainChinese("中国China"));
 9     }
10
11     public static boolean isContainChinese(String str) {
12
13         Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
14         Matcher m = p.matcher(str);
15         if (m.find()) {
16             return true;
17         }
18         return false;
19     }
20 }

在自己的例子里面,find起作用

 1 package sdf;
 2
 3 import java.util.regex.Matcher;
 4 import java.util.regex.Pattern;
 5
 6 public class d {
 7
 8     public static boolean isNumeric(String str) {
 9         for (int i = str.length(); --i >= 0;) {
10             if (!Character.isDigit(str.charAt(i))) {
11                 return false;
12             }
13         }
14         return true;
15     }
16     public static void main(String[] args) {
17         // TODO Auto-generated method stub
18
19         String s1="25";
20         String s2="补考";
21         Pattern pattern = Pattern.compile("\\d+");
22
23           Matcher matcher1 = pattern.matcher(s1);
24           //boolean b1= matcher1.matches();
25           boolean b1= matcher1.find();
26           System.out.println(b1);
27
28           Matcher matcher2 = pattern.matcher(s2);
29           //boolean b2= matcher2.matches();
30           boolean b2= matcher2.find();
31         System.out.println(b2);
32
33         //System.out.println(isNumeric(s1));
34        //System.out.println(isNumeric(s2));
35
36     }
37
38 }
时间: 2024-08-11 05:46:23

java 字符串中是否有数字的相关文章

C# 使用正则表达式去掉字符串中的数字,或者去掉字符串中的非数字

/// 去掉字符串中的数字 public static string RemoveNumber(string key)          {              return Regex.Replace(key, @"\d", "");          } //去掉字符串中的非数字public static string RemoveNotNumber(string key)  {      return Regex.Replace(key, @"

输入字符串取出字符串中的连续数字放入单独数组

public class ShowsNum { public Map getNums(String str){ HashMap<Integer,String> map=new HashMap<Integer,String>(); char [] chnum=str.toCharArray(); StringBuffer strbuffer=new StringBuffer(); int des=1; for(int i=0;i<chnum.length;i++){ //当前字

php+正则将字符串中的字母数字和中文分割

原文出处 如果一段字符串中出现字母数字还有中文混排的情况,怎么才能将他们区分开呢,经过一番思索,得到了如下代码,分享给大家 如:$str="php如何将字 符串中322的字母数字sf f45d和中文_分割?";  按数字或字母分割. <?php $str = "php如何将字 符串中322的字母数字Asf f45d和中文_分割?"; $array = preg_split("/([a-zA-Z0-9]+)/", $str, 0, PREG_

JAVA字符串中的转义字符 &quot; \ &quot;

在java字符串中如果出现斜杠,1.当成转义字符 " \ " 时,后面必须接八进制数字进行ASCII转义输出成其它字符,2.当成字符串斜杠直接输出时,必须用双斜杠 "\" 转义为单斜杠 ASCII参考八进制表:https://baike.baidu.com/item/ASCII/309296?fr=aladdin JAVA中比较特别的一点是:str.split("sep", limit)函数其第1个参数seperator分隔符字符串是要被正则解析

【Teradata SQL】从中文数字字母混合字符串中只提取数字regexp_substr

目标:从中文数字字母的字符串中只提取数字 sel regexp_substr('mint choc中文11国1','\d+') 原文地址:https://www.cnblogs.com/badboy200800/p/10792095.html

Excel-判断一个文本字符串中是否包含数字! 判断一个文本字符串是否是纯汉字!

0.判断一个文本字符串中是否包含数字!/判断一个文本字符串是否是纯汉字! 公式=IF(LENB(A1)=2*LEN(A1),”都是汉字“,“含有非汉字字符”) 解释函数: LEN(A1)#返回文本字符串中的字符个数:  ##双字字符*1*双字节字符个数+单字节字符*1*单字节字符个<=>计算字符个数: LENB(A1)#返回文本字符串中的字符个数.与双字节字符集(DBCS)一起使用.##双字节字符*2*双字节字符个数+单字节字符*1*单字节字符个数<=>计算字节个数: 字符:分为双

【Simple Java】Java字符串中常见的10个问题

下面是Java中10个最常见的关于字符串的问题. 怎样比较字符串?使用==还是equals() 简单的说,“==”用于判断引用是否相等,equals()用于判断值是否相等.除非你要比较两个字符串是否是同一个对象,否则你应该使用equals()方法.如果你知道字符串驻留的概念会更好. 对于敏感信息优先使用字符数组而不是字符串 字符串是不可变的,意味着一旦被创建,他们就会一直存在直到垃圾回收器回收它们.然而对于一个数组来说,你可以明确的改变它们的元素.使用这种方法,敏感信息(如密码)就不会长期存在于

Java字符串中常用字符占用字节数

java中一个char型的数据(也就是一个字符)占两个字节.而Java中常用的字符包括数字.英文字母.英文符号.中文汉字.中文符号等,若在字符串中包含里面的多种字符,它们是否都占两个字符呢?答案是否定的. public class CharBytes { public static void main(String[] args) { String s1 = "1234567";// 7个数字字符 byte[] b1 = s1.getBytes(); System.out.printl

获取字符串中最大的数字

/// <summary> /// 获取字符串最长的数字 /// </summary> /// <param name="inputStr">输入字符串</param> /// <returns>最长数字</returns> public string GetMaxLenNumber(string inputStr) {   //将字符串中的字符存放到数组中,便于处理   char[] strCharArray =