#include <iostream>#include<algorithm>#include<functional>using namespacestd; classteststring { Public: voidToupper (string& str);//Turn Capital voidTolower (string& str);//Turn lowercase voidTrimRight (string& str);//Remove the space behind voidTrimleft (string& str);//Remove the preceding space voidDeletechar (string& STR,CharCH);//remove a character from the string, and note that it's all removed . voidTestreplace ();//Replace a character in a string such as abcdef to replace AB with a CD BOOLStartwith (Const string& STR,Const string& Strstart);//string begins with a paragraph BOOLEndwith (Const string& STR,Const string& Strend);//string ends with a paragraph voidTestreverse ();//Flip String}; voidTeststring::toupper (string&str) {Transform (Str.begin (), Str.end (), Str.begin (),:: ToUpper); } voidTeststring::tolower (string&str) {Transform (Str.begin (), Str.end (), Str.begin (),:: ToLower); } voidTeststring::trimleft (string&str) {Str.erase (0, Str.find_first_not_of (' ')); } voidTeststring::trimright (string&str) {Str.erase (str.find_last_not_of (' ')+1); } voidTestString::D Eletechar (string& STR,Charch) {Str.erase (remove_if (Str.begin (), Str.end (), bind2nd (equal_to<Char>(), ch)), str.end ()); } voidTeststring::testreplace () {stringstr ="abcdef"; stringStrsub ="AB"; Str.replace (Str.find (strsub), Strsub.size (),"CD"); cout<<str.c_str () <<Endl; } BOOLTeststring::startwith (Const string& STR,Const string&Strstart) { if(Str.empty () | |Strstart.empty ()) { return false; } returnStr.compare (0, Strstart.size (), strstart) = =0?true:false; } BOOLTeststring::endwith (Const string& STR,Const string&strend) { if(Str.empty () | |Strend.empty ()) { return false; } returnStr.compare (Str.size ()-strend.size (), Strend.size (), strend) = =0?true:false; } //The process of flipping Chinese characters will appear garbled, because the method is flipped by CharvoidTeststring::testreverse () {stringSTR1 ="Zhang Dongxhen"; Std::reverse (Str1.begin (), Str1.end ()); stringSTR2 =""; Str2.assign (Str1.rbegin (), Str1.rend ()); }
Turn from:
11533329
Some uses of C + + on string