Solved

Validating a string...

Posted on 2002-06-19
2
181 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
Comment Utility
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
Comment Utility
Thanks much!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now