1. 程式人生 > >C++ Builder中的字串替換函式

C++ Builder中的字串替換函式

UnicodeString __fastcall StringReplace(

        const System::UnicodeString S,

        const System::UnicodeString OldPattern,

        const System::UnicodeString NewPattern

,

        TReplaceFlags Flags)

說明:

1.引數S,需要修改的字串

2.引數OldPattern,需要替換的子串

3.引數NewPattern,用以替換的新子串

4.引數 TReplaceFlags Flags 替換標識,包含rfReplaceAll和rfIgnoreCase,rfReplaceAll用來確定是否替換全部的子串,rfIgnoreCase用來確定是否區分字母的大小寫。

例子:

AnsiString str = "你帥,你很帥,你非常帥";

AnsiString sNewStr = StringReplace(str,"帥","漂亮",TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);

retrun sNewStr;

 

返回值:"你漂亮,你很漂亮,你非常漂亮"