0

I can't find a function that will replace one substring with another.

For example, I have a component LabeledEdit and I want to write some text in it. After that, I want to check if there are some spaces in the text and replace them with %.

String text;
text = LabeledEdit1->Text.Trim();
text = text. <- some replace function to replace " " to "%"
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
forritarik
  • 35
  • 4

2 Answers2

4

You can use the RTL's System::Sysutils::StringReplace() function:

Replaces occurrences of a substring within a string.

StringReplace replaces occurrences of the substring specified by OldPattern with the substring specified by NewPattern in the string Source.

#include <System.SysUtils.hpp>

String text;
text = LabeledEdit1->Text.Trim();
text = StringReplace(text, _D(" "), _D("%"), TReplaceFlags() << rfReplaceAll);
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
0

with this code

#include <System.SysUtils.hpp>

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

everything working fine

forritarik
  • 35
  • 4
  • 2
    Rather than post your own answer that just quotes the solution that worked for you, it is customary to mark as accepted the answer that gave you the solution. See [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) and [What does it mean when an answer is "accepted"?](https://stackoverflow.com/help/accepted-answer). You have been a member of StackOverflow for over a year and have posted many questions, but you have not accepted any answers given to you so far. – Remy Lebeau Sep 21 '19 at 06:22