java判斷字串是否為數字或中文或字母
來自:晞瀾
1.判斷字串是否僅為數字:
1>用JAVA自帶的函式
public static boolean isNumeric(String str){
for (int i = str.length();--i>=0;){
if (!Character.isDigit(str.charAt(i))){
return false;
}
}
return true;
}
2>用正則表示式
public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}
3>用ascii碼
public static boolean isNumeric(String str){
for(int i=str.length();--i>=0;){
int chr=str.charAt(i);
if(chr<48 || chr>57)
return false;
}
return true;
}
2.判斷一個字串的首字元是否為字母
public static boolean test(String s)
{
char c = s.charAt(0);
int i =(int)c;
if((i>=65&&i<=90)||(i>=97&&i<=122))
{
return true;
}
else
{
return false;
}
}
public static boolean check(String fstrData)
{
char c = fstrData.charAt(0);
if(((c>='a'&&c<='z') || (c>='A'&&c<='Z')))
{
return true;
}else{
return false;
}
}
3 .判斷是否為漢字
public boolean vd(String str){
char[] chars=str.toCharArray();
boolean isGB2312=false;
for(int i=0;i<chars.length;i++){
byte[] bytes=(""+chars[i]).getBytes();
if(bytes.length==2){
int[] ints=new int[2];
ints[0]=bytes[0]& 0xff;
ints[1]=bytes[1]& 0xff;
if(ints[0]>=0x81 && ints[0]<=0xFE && ints[1]>=0x40 && ints[1]<=0xFE){
isGB2312=true;
break;
}
}
}
return isGB2312;
}
相關推薦
java判斷字串是否為數字或中文或字母
來自:晞瀾 1.判斷字串是否僅為數字: 1>用JAVA自帶的函式 public static boolean isNumeric(String str){ for (int i = str.length();--i>=0;){ if (!Ch
java判斷字串是否為數字或小數
public static boolean isNumeric(String str){ Pattern pattern = Pattern.compile("[0-9]*"); if(str.indexOf(".")>0){//判斷是否有小數點 if(str.
java 判斷字串是否為數字(包含負數)
public static void main(String[] args){ System.out.println(AssistController.isNumeric("-77"));}public static boolean isNumeric(String str){ Pattern pa
Java判斷字串是否為數字
package com.java.demo; import java.util.regex.Matcher; import java.util.regex.Pattern; public clas
java判斷字串是否為數字、字母、漢字
public class ZhStringUtil { /** * 判斷字串是否為數字 * @param str * @return */ pu
JAVA判斷字串是否為數字或者是否以0開頭
public static boolean isNumeric(String str){ if(str.matches("\\d*"){ return true; }else{ return false; } }4.用ascii碼 public static boolean isNumeric(Strin
java判斷字串是否為正負整數或浮點數
package org.fiend.basetest; import org.apache.commons.lang3.StringUtils; import java.util.regex.Pattern; /** * 判斷字串是否為正負整數或浮點數 * @author Adminis
Java中判斷字串是否為數字的五種方法
//方法一:用JAVA自帶的函式 public static boolean isNumeric(String str){ for (int i = str.length();--i>=0;){ if (!Character.isDigit(st
java中判斷字串是否為數字的方法 StringUtil包函式
java中判斷字串是否為數字的方法: 1.用JAVA自帶的函式 public static boolean isNumeric(String str){ for (int i = 0; i < str.length(); i++){ System.out.p
java中判斷字串是否為數字的三種方法
1用JAVA自帶的函式 public static boolean isNumber(String str){ boolean re = true; for(int i=0;i<str.length();i++){ if(!Character.isDigit(str
Java中判斷字串是否為數字的幾種方法
原文地址:http://blog.csdn.net/u013066244/article/details/53197756 用JAVA自帶的函式 public static boolean isNumericZidai(String str) {
Java判斷字串是否為純數字(0-9)
public static boolean isNumeric(String str){ / * Copyright: http://javapub.iteye.com/blog/666544 * / for
java中判斷字串是否為數字的方法的幾種方法
java中判斷字串是否為數字的方法: 1.用JAVA自帶的函式 public static boolean isNumeric(String str){ for (int i = 0; i < str.length(); i++){ System.out.
js 判斷字串是否為數字(正整數)
/** * 判斷字串是否為數字 * @param nubmer * @returns {boolean} */ function checkRate(nubmer) { //判斷正整數/[1−9]+[0−9]∗]∗/ var re = /^[0-9]+.?[0-9]*/;
java 判斷字串是否為亂碼
以下是一個事例: import java.util.regex.Matcher; import java.util.regex.Pattern; public class MessyCodeCheck { public static boolean isChinese(char c) {
java判斷字串是否為亂碼
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
正則表示式判斷字串是否為數字
IF cl_abap_matcher=>matches( pattern = '^(-?[1-9]\d*(\.\d*[1-9])?)|(-?0\.\d*[1-9])$' text = '1.01' ) = abap_true. WRITE '數字'. ELSE.
Java 判斷字串不為空得條件
首先,區分空串和null串 1、 空串”“是長度為0的字串,它有自己的串長度(0)和內容(空),判斷一個字串為空的方法: if (str.length() == 0); 1 或 if (str.equals(“”)); 1 2、 null串表示目
java 判斷字串是否為json格式
public static boolean isJson(String content) { try { JS
判斷字串是否為數字
1.用正則表示式 import java.util.regex.Pattern 和 java.util.regex.Matcher /** * 利用正則表示式判斷字串是否是數字 * @param str * @return */ publi