paip.c++ bcb string 转换操作大总结.

paip.c++ bcb string 转换操作大总结.

1.StringTrimleft  (customzi)
2.int2str   (customzi)
3.replace_all  (customzi)
4.StringTrimleftAndTab  (customzi)
5.UnicodeString >>string          string line=  this->Edit1->Text.t_str();
6.stirng  >> String                 (  UnicodeString strA = stirng.c_str();)
7.StrToInt   (vcl/sysUtil.hpp)


作者Attilax ,  EMAIL:1466519819@qq.com
来源:attilax的专栏
地址:http://blog.csdn.net/attilax

 


void StringTrimleftCa(::std::string & str)
{
//left
str.erase(0,str.find_first_not_of("\r\t\n "));
//str.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
//right
//str.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
}

 string StringTrimleft(string str)
 {
    string str2=str;
    StringTrimleftCa(str2);
    return str2;

 }
 
 #include <strstream>
 string int2str(int&i) {
 string s;
stringstream ss(s);
ss <<i;

return ss.str();
}


string&   replace_all(string&   str,const   string&   old_value,const   string&   new_value)
{
    while(true)   {
        string::size_type   pos(0);
        if(   (pos=str.find(old_value))!=string::npos   )
            str.replace(pos,old_value.length(),new_value);
        else   break;
    }
    return   str;
}

 

  string StringTrimleftAndTab(string str)
 {
    string str2=str;
     treex* tx=new treex();
 string line2= tx-> convertLeft2space (str );

 string lineTrimed=StringTrimleft( line2);
    return lineTrimed;

 }
 
 
 
string treex::convertLeft2space(string line)
{
  line=replace_all(line,"│","  ");
   line=replace_all(line,"├","  ");
    line=replace_all(line,"─","  ");
    line=replace_all(line,"└","  ");

 

  return line;
}


 int treex::indentLevel(string line)
{
 string line2=  convertLeft2space (line );

 string lineTrimed=StringTrimleft( line2);
 int lineTrimedLenth=lineTrimed.length();
   int n= line2.length()- lineTrimedLenth ;
   int level=n/4;
   return level;
}

posted @ 2013-10-14 17:42  attilaxAti  阅读(33)  评论(0编辑  收藏  举报