代码之家  ›  专栏  ›  技术社区  ›  Holograham

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

  •  0
  • Holograham  · 技术社区  · 16 年前

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

    2 回复  |  直到 16 年前
        1
  •  1
  •   Dustin Getz sunsations    16 年前

    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_if.html

        2
  •  0
  •   Chris Bednarski    16 年前