Solved

Validating a string...

Posted on 2002-06-19
2
190 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 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

617 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