Reputation: 35
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 "%"
Upvotes: 0
Views: 1496
Reputation: 35
with this code
#include <System.SysUtils.hpp>
String text;
text = LabeledEdit1->Text.Trim();
text = StringReplace(text, _D(" "), _D("%"), TReplaceFlags() << rfReplaceAll);
everything working fine
Upvotes: 0
Reputation: 596497
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);
Upvotes: 4