STD::String replace
-
Hi, The application i'm writing at the moment is multi-lingual so we're working with std::strings. I'm generating an html on-the-fly in my application. I do it by using place holders so i need an efficient "replace" function but i coulnd't find an efficient replace methond for std::strings. Does anybody have an idea? thanks in advance. Snir Singleton Technologies Ltd.
-
Hi, The application i'm writing at the moment is multi-lingual so we're working with std::strings. I'm generating an html on-the-fly in my application. I do it by using place holders so i need an efficient "replace" function but i coulnd't find an efficient replace methond for std::strings. Does anybody have an idea? thanks in advance. Snir Singleton Technologies Ltd.
String class does have a replace method.
-
Hi, The application i'm writing at the moment is multi-lingual so we're working with std::strings. I'm generating an html on-the-fly in my application. I do it by using place holders so i need an efficient "replace" function but i coulnd't find an efficient replace methond for std::strings. Does anybody have an idea? thanks in advance. Snir Singleton Technologies Ltd.
Define efficient - i.e. why
std::string::replace
isn't suitable. You may be better off generating a new string using original string and placeholder replacements, i.e. scan through the original string, copying it to the new one, and when you see a placeholder, copy the replacement text to the new string rather than the placeholder (which you (obviously) step over). -
String class does have a replace method.
Igor Vigdorchik wrote:
String class does have a replace method.
std::string even has 9 replace functions! :~
-
Hi, The application i'm writing at the moment is multi-lingual so we're working with std::strings. I'm generating an html on-the-fly in my application. I do it by using place holders so i need an efficient "replace" function but i coulnd't find an efficient replace methond for std::strings. Does anybody have an idea? thanks in advance. Snir Singleton Technologies Ltd.
snir_ya wrote:
The application i'm writing at the moment is multi-lingual so we're working with std::strings.I'm generating an html on-the-fly in my application. I do it by using place holders so i need an efficient "replace" function but i coulnd't find an efficient replace methond for std::strings.
You need to write a function that copies your string contents to a new string object thereby replacing all 'place holders' in one pass with the actual strings. Try
find_first_of
to find a place holder.