【问题标题】:UnicodeString replace one substring with anotherUnicodeString 用另一个子字符串替换一个子字符串
【发布时间】:2019-09-20 12:15:13
【问题描述】:

我找不到将一个子字符串替换为另一个子字符串的函数。

例如,我有一个组件LabeledEdit,我想在其中写一些文本。之后,我想检查文本中是否有一些空格并将它们替换为%

String text;
text = LabeledEdit1->Text.Trim();
text = text. <- some replace function to replace " " to "%"

【问题讨论】:

标签: c++ string replace c++builder


【解决方案1】:

您可以使用 RTL 的 System::Sysutils::StringReplace() 函数:

替换字符串中出现的子字符串。

StringReplace 将 OldPattern 指定的子字符串替换为字符串 Source 中 NewPattern 指定的子字符串。

#include <System.SysUtils.hpp>

String text;
text = LabeledEdit1->Text.Trim();
text = StringReplace(text, _D(" "), _D("%"), TReplaceFlags() << rfReplaceAll);

【讨论】:

    【解决方案2】:

    使用此代码

    #include <System.SysUtils.hpp>
    
    String text;
    text = LabeledEdit1->Text.Trim();
    text = StringReplace(text, _D(" "), _D("%"), TReplaceFlags() << rfReplaceAll);
    

    一切正常

    【讨论】:

    猜你喜欢
    • 2011-04-06
    • 2011-06-06
    • 2014-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-18
    • 2013-12-03
    • 1970-01-01
    相关资源
    最近更新 更多