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;

 

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

猜你喜欢

转载自blog.csdn.net/AquariusYuxin/article/details/81016116