Some uses of C + + on string

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.