Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Validating a string...

Posted on 2002-06-19
2
Medium Priority
?
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

730 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