码迷,mamicode.com
首页 > 其他好文 > 详细

判断是不是纯数字字符串

时间:2017-06-15 20:36:32      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:std   str   log   false   git   class   ret   bool   bsp   

判断一个字符串是不是纯数字字符串

注:1、当字符串首位是0的时候,如“-0123345”或者“01232345”,此处认为是合法的纯数字字符串

  2、当字符串全部是0的时候,如“0000”,此处也认为是合法的纯数字字符串

 1     bool IsAllDigit(const std::string &sConnect)
 2     {
 3         if (sConnect.empty() )
 4         {
 5             return false;
 6         }
 7 
 8         std::string _sConnect = sConnect;
 9         if (_sConnect[0] == -)
10         {
11             //此处-1是为了不被最后一位结束符影响,可以不-1
12             _sConnect = sConnect.substr(1,sConnect.length() - 1);
13             14         }
15         if (_sConnect.empty() )
16         {
17             return false;
18         }
19 
20         for (size_t i = 0; i < _sConnect.length(); i++)
21         {
22             if (_sConnect[i] < 0 || _sConnect[i] > 9)
23             {
24                 return false;
25             }
26         }
27 
28         return true;
29     }

 

判断是不是纯数字字符串

标签:std   str   log   false   git   class   ret   bool   bsp   

原文地址:http://www.cnblogs.com/LYF-LIUDAO/p/7019595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!