473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

checking if a string can be a interger

Is there a way to check if a string can be a interger without crashing the program?
Apr 6 '07 #1
2 1434
ghostdog74
511 Expert 256MB
Is there a way to check if a string can be a interger without crashing the program?
a few ways
Expand|Select|Wrap|Line Numbers
  1. >>> a="123"
  2. >>> if a.isdigit():
  3. ...  print "it is digit"
  4. ...
  5. it is digit
  6.  
  7.  
Expand|Select|Wrap|Line Numbers
  1. >>> try: int(a)
  2. ... except: print "not integer"
  3. ...
  4. 123
  5. >>> a = "32sdfs"
  6. >>> try: int(a)
  7. ... except: print "not integer"
  8. ...
  9. not integer
  10.  
Apr 6 '07 #2
Thank you.
Apr 6 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: rainmaker1234 | last post by:
Its very simple in VC++. In the followeing code I have declared a String, and a double than I am taking the string and converting it into Double. getch() at the end is only to pause the screen so...
0
by: Paul Steele | last post by:
Is there a reliable way to check for the existence of wireless adapters in a system? I thought it was going to be simple using WMI's Win32_NetworkAdapter class, but the information at MSDN does not...
3
by: Martin | last post by:
Hi, How can I convert a string type to a number, f.example an Interger? Thanks Martin
2
by: guoqi zheng | last post by:
We can enum to represent a interger using a string. But how can we use enum to represent string below is what I want to achieve. Public Enum country Netherlands = "nl" America = "US" France...
27
by: fuch6921 | last post by:
I want to read in an Octal number argument and have it stored as an octal number. For instance the user will type: ./a.out 777 and it will store the octal number 777. But it atoi does this as an...
3
by: kathy | last post by:
I want to know what is the easy way to check if a string is a number or not? the number can be int, float, double, scientific,... what is the easy way for only interger?
24
by: Derek Hart | last post by:
Is there an efficient line of code to count the number of instances of one string within another. If I have the sentence: "I want to go to the park, and then go home." It would give me a...
4
by: Patient Guy | last post by:
Does anyone have any coding rules they follow when doing argument checking? When arguments fail during check, do you return from the call with an ambiguous return value, or do you throw...
125
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.