Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从SQLCHAR对象解析出非字母数字字符_C++_Sql - Fatal编程技术网

C++ 从SQLCHAR对象解析出非字母数字字符

C++ 从SQLCHAR对象解析出非字母数字字符,c++,sql,C++,Sql,我目前有一组数据库查询中的SQLCHAR对象。查询结果存储在std::string中,然后绑定到各个SQLCHAR变量。为了删除任何非字母数字字符,需要解析其中一些变量。这里最好的方法是什么 我已经实现了对std::string的基本解析 for (std::string::iterator i = str.end()-1; i >= str.begin(); --i) { if ( !isalpha(*i) && !isdigit(*i) ) {

我目前有一组数据库查询中的SQLCHAR对象。查询结果存储在std::string中,然后绑定到各个SQLCHAR变量。为了删除任何非字母数字字符,需要解析其中一些变量。这里最好的方法是什么

我已经实现了对std::string的基本解析

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

但是现在我遇到了将SQLCHAR转换为std::string然后再转换回来的问题。有更好的方法吗

您是否希望易于维护或性能更好

boost正则表达式可以帮助进行维护


对于性能,我会查看标准STL。。。std::remove_if算法考虑这个伪代码

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


很遗憾,我无法使用Boost。最好易于维护。