String es = s; es.replace('\'', "''");
String es = s; int pos = 0; while ( (pos = es.Find('\'', pos)) >= 0) { es.Insert(pos, '\''); pos += 2; }
String es; for(const char *q = s; *q; q++) { es.Cat(*q); if(*q == '\'') es.Cat('\''); }
String es; for(const char *q = s; *q; q++) { es.Cat(*q); if(*q == '\'') es.Cat('\''); }
String replace_string(String& s1, String& find, String replace){ String string_result; int start_pos = 0; int found_pos = 0; int find_len = find.GetCount(); int s1_count = s1.GetCount(); while(((found_pos=s1.Find(find, start_pos))!=-1)){ string_result.Cat(s1.Mid(start_pos, found_pos - start_pos)); string_result.Cat(replace); start_pos = found_pos + find_len; }; if(start_pos<s1.GetCount()) string_result.Cat(s1.Mid(start_pos)); return (string_result); }
template <class B> void AString<B>::Replace(const tchar *find, int findlen, const tchar *replace, int replacelen) { String r; int i = 0; const tchar *p = Begin(); for(;;) { int j = Find(findlen, find, i); if(j < 0) break; r.Cat(p + i, j - i); r.Cat(replace, replacelen); i = j + findlen; } r.Cat(p + i, GetCount() - i); *this = r; }
void Replace(const String& find, const String& replace) { Replace(~find, find.GetCount(), ~replace, replace.GetCount()); } void Replace(const tchar *find, const tchar *replace) { Replace(find, strlen(find), replace, strlen(replace)); }
template <class B> void AString<B>::Replace(const tchar *find, int findlen, const tchar *replace, int replacelen) { String r; int i = 0; const tchar *p = Begin(); for(;;) { int j = Find(findlen, find, i); if(j < 0) break; r.Cat(p + i, j - i); r.Cat(replace, replacelen); i = j + findlen; } r.Cat(p + i, GetCount() - i); *this = r; }
void Replace(const String& find, const String& replace) { Replace(~find, find.GetCount(), ~replace, replace.GetCount()); } void Replace(const tchar *find, const tchar *replace) { Replace(find, strlen(find), replace, strlen(replace)); }
template <class B> void AString<B>::Replace(const tchar *find, int findlen, const tchar *replace, int replacelen) { String r; int i = 0; const tchar *p = B::Begin(); // Added "B::" for(;;) { int j = Find(findlen, find, i); if(j < 0) break; r.Cat(p + i, j - i); r.Cat(replace, replacelen); i = j + findlen; } r.Cat(p + i, B::GetCount() - i); // Added "B::" *this = r; }
#include <Core/Core.h> #include <StringReplacer/StringReplacer.h> CONSOLE_APP_MAIN { String template_str = "This is an example\n" "!PARTNER! lives in !CITY!\n" "Price of !PRODUCT.NAME! is !PRODUCT.PRICE!\n" "This is some text at the end."; VectorMap<String, Value> template_args; template_args.Add("PARTNER", "John Doe"); template_args.Add("CITY", "Budapest"); template_args.Add("PRODUCT.NAME", "Disk"); template_args.Add("PRODUCT.PRICE", "12.34"); StringReplacer replacer; replacer.SetTemplate(template_str); String result; replacer.Cat(template_args, result); Cout() << result; Cout() << "\n\nDone\n"; }