mercredi 7 mai 2014

chaîne de caractères Rechercher Remplacer, grep, strpos ou concat nouveau un c / c ++ efficacité - Stack Overflow


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&param2=string&param3=needs&param4=a&param5=lot ... &param25=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&param2=string&param3=needs&param4=a&param5=lot ... &param25=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


Related Posts:

0 commentaires:

Enregistrer un commentaire