Linux C判断字符串是否为数字

Title:Linux C判断字符串是否为数字  --2013-10-14 15:54

#include <ctype.h>
#include <string.h>
    int IsInt(char* str)
    {
        int len;
        len = strlen(str);
        int i=0;
        for(i;i<len;i++)
        {
            if(!(isdigit(str[i])))
                return 0;
        }
        return 1;
    }

  

时间: 2024-08-05 23:15:42

Linux C判断字符串是否为数字的相关文章

字符串--java中判断字符串是否为数字的方法的几种方法?

ava中判断字符串是否为数字的方法: 1.用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = 0; i < str.length(); i++){ System.out.println(str.charAt(i)); if (!Character.isDigit(str.charAt(i))){ return false; } } return true; } 2.用正则表达式 首先要import java.u

C语言判断字符串是否为数字

判断一个字符串是否为数字, 听起来很简单,实现还是有点难度的. 最近写了一个,如下: #define IS_BLANK(c) ((c) == ' ' || (c) == '\t') #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9') #define IS_ALPHA(c) ( ((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= '

java python oracle判断字符串是否为数字的函数

java public boolean isNumeric(String str){ Pattern pattern = Pattern.compile("^-?[0-9]+\\.?[0-9]+"); Matcher isNum = pattern.matcher(str); if( !isNum.matches() ){ return false; } return true; } python def isNum(value): try: int(value) + 1 except

判断字符串是否为数字格式

import java.util.Scanner; /*判断字符串是否是数字格式*/ public class CheckNum {    public static void main(String args[]){    Scanner scanner = new Scanner(System.in);    System.out.println("请输入要验证的字符串:");    String str = scanner.next();    char c[] = str.to

C#判断字符串是否是数字

1 /// <summary> 2 /// 判断字符串是否是数字 3 /// </summary> 4 public static bool IsNumber(string s) 5 { 6 if (string.IsNullOrWhiteSpace(s)) return false; 7 const string pattern = "^[0-9]*$"; 8 Regex rx = new Regex(pattern); 9 return rx.IsMatch

java中判断字符串是否为数字的方法的几种方法

Java中判断字符串是否为数字的方法: 1.用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = 0; i < str.length(); i++){ System.out.println(str.charAt(i)); if (!Character.isDigit(str.charAt(i))){ return false; } } return true; } 2.用正则表达式 首先要import java.

判断字符串string是数字、json结构、xml结构

import org.json.JSONException; import org.json.JSONObject; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; public class StringTest { /** * @param args */ public static void main(String[] args) { String string1 = "123"; Strin

判断字符串全为数字

1 判断字符串全为数字 1.1 直接调用 isNumeric 方法 1.1.1 引入commons依赖包 <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.6</version> </dependency>   1.1.2 通过  StringUtils类 调用

js判断字符串是否是数字

今天做项目的时候,遇到一个问题,是需要判断一个字符串是否是数字.我的方法是用Nmuber(str)==NaN(还试了Nmuber(str)=='NaN'),发现是错的,不管我的str是什么东西,Nmuber(str)==NaN都是false.后来,才发现,这样是不对的.正确的做法是isNaN(str),当isNaN(str)是false时,表示是str是数字,为true时,表示str不是数字.(注意,当str是null或""时,值是false)