what function do we use?

Hi,

What function do we use in order to identify between a letter and a number in a string?
You can look at the ascii value.

Or you can use isalpha and those functions.

http://cplusplus.com/reference/clibrary/cctype/
But how do we check if the string contain both number and letter?
You can check your string character by character using a loop and the cctype as ultifinitus suggested.

If you need to keep your std::string format, you can use :
http://www.cplusplus.com/reference/string/string/data/ or
http://www.cplusplus.com/reference/string/string/c_str/ to work directly with the string as if it was a char*
Last edited on
I am sorry, I am a bit slow in this C++ plus I am new to it.

Can you give me an example on how to use loop for checking the string?
1
2
3
4
5
6
7
 string mystring = "adjkfal;jeifnawfklesfnr739280728907182903";

 for (int temp = 0; temp < mystring.size(); temp++){
  if (isalpha(mystring[temp]){
   //do whatever you want if it's a letter
  }
 }
Great! It works. Thanks!
Topic archived. No new replies allowed.