Solved

Validating a string...

Posted on 2002-06-19
2
183 Views
Last Modified: 2010-05-18
Hello-

Here is my problem.  I'm trying to parse a string that is entered by a user to make it conform to certain rules.

For example I needed to do this with a phone number so the function would strip out all of the non-numeric characters.  White space and "-", "(", and so-on.

My function that accomplishes this is

void TForm1::StripPhoneNumber(char * dest, char * src)
{
  while(*src)
  {
    if(isdigit(*src))
    {
      *(dest++) = *src;
    }

    src++;
  }

  *dest = 0;
}

It works well, but now i'm trying to do something similar but that keeps all letters and digits.  For instance,
1-800-ABC-DEFG would still return 1800ABCDEFG, and not just 1800.  

All I really need is an isletter equivalent to isdigit to put in the if statement.  Does such a function exist?

Thanks!
0
Comment
Question by:NJordan72
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 25 total points
ID: 7093421
Use 'isalnum()' instead:

int isalnum( int c );

int iswalnum( wint_t c );

Each of these routines returns true if c is a particular representation of an alphanumeric character.


Return Value

isalnum returns a non-zero value if either isalpha or isdigit is true for c, that is, if c is within the ranges A – Z, a – z, or 0 – 9. iswalnum returns a non-zero value if either iswalpha or iswdigit is true for c. Each of these routines returns 0 if c does not satisfy the test condition.

0
 

Author Comment

by:NJordan72
ID: 7093466
Thanks much!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

775 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question