我想要替换10多个不同的字符串。现在,我正在使用手动方法,如下面的代码所示。
StringReplace(StringReplace(StringReplace(StringReplace(
StringReplace(StringReplace(StringReplace(MyEditor->Text,
"one","ab",TReplaceFlags()<< rfReplaceAll << rfIgnoreCase),
"two","cd",TReplaceFlags()<< rfReplaceAll << rfIgnoreCase),
"three","ef",TReplaceFlags()<< rfReplaceAll << rfIgnoreCase),
"four","gh",TReplaceFlags()<< rfReplaceAll << rfIgnoreCase),
"five","ij",TReplaceFlags()<< rfReplaceAll << rfIgnoreCase),
"six","kl",TReplaceFlags()<< rfReplaceAll << rfIgnoreCase),
"seven","mn",TReplaceFlags()<< rfReplaceAll << rfIgnoreCase);
...so on and on.
所以,我想知道如何使用更实用和灵活的方法替换许多字符串。也许通过使用特定的功能?
非常感谢。
答案 0 :(得分:1)
RTL没有用于此目的的功能。你必须自己编写,例如:
curl -i -X GET http://localhost:10313/myservice/healthz
然后你可以这样称呼它:
struct StringReplacePattern
{
String OldPattern;
String NewPattern;
};
String __fastcall MultiStringReplace(const String S, const StringReplacePattern *Patterns, int NumPatterns, TReplaceFlags Flags)
{
String Result = S;
for (int i = 0; i < NumPatterns; ++i)
Result = StringReplace(Result, Patterns[i].OldPattern, Patterns[i].NewPattern, Flags);
return Result;
}