Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Validating a string...

Posted on 2002-06-19
2
Medium Priority
?
197 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 100 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

877 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