im interested in your experience with c/c++ find, find_first_of, replace, strpos, grep and concat. what is the most efficient method for replacing content in strings.
- no string replaces appear more than once per string
- the resulting string will not be the same length as the original.
- the original and final string will be less thn 2000 chars
- approximately 25 string replaces
- the needle remains consistent per haystack
ill test them, simply gathering options at this point.
here is the application at hand: a url string that needs extensive massaging. ie. almost all parameters will change, although the value will remain the same. from
param1=this¶m2=string¶m3=needs¶m4=a¶m5=lot ... ¶m25=work
to
what=this&method=string&will=needs&work=a&the=lot ... &best=work
i currently use a needle/haystack function that works on the existing string.
void findAndReplace(string& haystack, const string& needle, const string& replace) {
size_t len = needle.size();
if (haystack.size() < len)
return;
size_t pos = haystack.find(needle);
if (pos != string::npos)
haystack.replace(pos, len, replace);
}
i dont mind using char*, string, streams, grep or other. and building a new string is also an option.
thanks
im interested in your experience with c/c++ find, find_first_of, replace, strpos, grep and concat. what is the most efficient method for replacing content in strings.
- no string replaces appear more than once per string
- the resulting string will not be the same length as the original.
- the original and final string will be less thn 2000 chars
- approximately 25 string replaces
- the needle remains consistent per haystack
ill test them, simply gathering options at this point.
here is the application at hand: a url string that needs extensive massaging. ie. almost all parameters will change, although the value will remain the same. from
param1=this¶m2=string¶m3=needs¶m4=a¶m5=lot ... ¶m25=work
to
what=this&method=string&will=needs&work=a&the=lot ... &best=work
i currently use a needle/haystack function that works on the existing string.
void findAndReplace(string& haystack, const string& needle, const string& replace) {
size_t len = needle.size();
if (haystack.size() < len)
return;
size_t pos = haystack.find(needle);
if (pos != string::npos)
haystack.replace(pos, len, replace);
}
i dont mind using char*, string, streams, grep or other. and building a new string is also an option.
thanks
0 commentaires:
Enregistrer un commentaire