tags:

views:

137

answers:

2

I currently have a bunch of SQLCHAR objects from a database query. The query results are stored in a std::string and then binded to the individual SQLCHAR variables. Some of these variables need to be parsed in order to remove any non-alphanumeric characters. What is the best approach here?

I have implemented a basic parsing of a std::string ...

for (std::string::iterator i = str.end()-1; i >= str.begin(); --i)
{
    if ( !isalpha(*i) && !isdigit(*i) ) 
    {
        str1.erase(i);
    } 
}

But now I have the problem of converting a SQLCHAR to a std::string and then back again. Is there a better way to do this?

A: 

Are you looking for ease of maintenance or better performance?

boost regex can help with maintenance

For performace i'd look into the standard STL ... std::remove_if algorithm

Chris Bednarski
unfortunately I cannot use Boost. Ease of maintenance would be preferred.
Holograham
+1  A: 

consider this pseudocode

bool is_not_alnum(char c){return !isalnum(c);}
unsigned char* s = ()blah_as_sql_char; //somehow its gotta cast to cstr right?
std::remove_if(s, strlen(s), is_not_alnum);
SQLCHAR result = (SQLCHAR)s; //cast it back however

http://www.cplusplus.com/reference/clibrary/cctype/isalnum/
http://www.sgi.com/tech/stl/remove%5Fif.html

Dustin Getz