changing a part of a string
-
hello everybody! I'm having trouble in changing a certain string. if I have have that string: strNum = 1234&567; the thing is that I want to change the "&" sign to the "and" so my string will be 1234and567. can anyone help me with that somehow??? :confused: Thanks!
-
hello everybody! I'm having trouble in changing a certain string. if I have have that string: strNum = 1234&567; the thing is that I want to change the "&" sign to the "and" so my string will be 1234and567. can anyone help me with that somehow??? :confused: Thanks!
Does CString have a Replace function ? I don't think that std::string does. Either way, either you or a wrapper needs to allocate new memory and construct a new string ( char * ), because you want to replace one character with 3. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
hello everybody! I'm having trouble in changing a certain string. if I have have that string: strNum = 1234&567; the thing is that I want to change the "&" sign to the "and" so my string will be 1234and567. can anyone help me with that somehow??? :confused: Thanks!
you should tokenize the string with a delimiter of your choice, then append the tokens back into your string. // code for tokenizing, taken from http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html[^] void Tokenize(const string& str, vector& tokens, const string& delimiters = " ") { // Skip delimiters at beginning. string::size_type lastPos = str.find_first_not_of(delimiters, 0); // Find first "non-delimiter". string::size_type pos = str.find_first_of(delimiters, lastPos); while (string::npos != pos || string::npos != lastPos) { // Found a token, add it to the vector. tokens.push_back(str.substr(lastPos, pos - lastPos)); // Skip delimiters. Note the "not_of" lastPos = str.find_first_not_of(delimiters, pos); // Find next "non-delimiter" pos = str.find_first_of(delimiters, lastPos); } }
-
you should tokenize the string with a delimiter of your choice, then append the tokens back into your string. // code for tokenizing, taken from http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html[^] void Tokenize(const string& str, vector& tokens, const string& delimiters = " ") { // Skip delimiters at beginning. string::size_type lastPos = str.find_first_not_of(delimiters, 0); // Find first "non-delimiter". string::size_type pos = str.find_first_of(delimiters, lastPos); while (string::npos != pos || string::npos != lastPos) { // Found a token, add it to the vector. tokens.push_back(str.substr(lastPos, pos - lastPos)); // Skip delimiters. Note the "not_of" lastPos = str.find_first_not_of(delimiters, pos); // Find next "non-delimiter" pos = str.find_first_of(delimiters, lastPos); } }
Thanks! :-) understood!
-
hello everybody! I'm having trouble in changing a certain string. if I have have that string: strNum = 1234&567; the thing is that I want to change the "&" sign to the "and" so my string will be 1234and567. can anyone help me with that somehow??? :confused: Thanks!
have u tried strstr() of the string.h ?....itz used to find a string inside a srring!!!!! cheerz.....:-D "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
-
hello everybody! I'm having trouble in changing a certain string. if I have have that string: strNum = 1234&567; the thing is that I want to change the "&" sign to the "and" so my string will be 1234and567. can anyone help me with that somehow??? :confused: Thanks!
If this String is Object of CString then you simply use this Function CString strNum = "1234&567";
strNum.Replace("&","and");
[Vote One Here, Complete my Survey....] Alok Gupta
visit me at http://www.thisisalok.tk "I Think Believe this Will Help" -
If this String is Object of CString then you simply use this Function CString strNum = "1234&567";
strNum.Replace("&","and");
[Vote One Here, Complete my Survey....] Alok Gupta
visit me at http://www.thisisalok.tk "I Think Believe this Will Help"yeah I know, but I was looking for string, not CString. but, I don't quite understand the difference between the two. I know that CString is microsoft's string class, and it has more functionality, but what are the disadvantages of CString comparing to string?
-
have u tried strstr() of the string.h ?....itz used to find a string inside a srring!!!!! cheerz.....:-D "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
now thats a useful info! :-)
-
yeah I know, but I was looking for string, not CString. but, I don't quite understand the difference between the two. I know that CString is microsoft's string class, and it has more functionality, but what are the disadvantages of CString comparing to string?
Cstring is MFC dependent class whereas STL string as no such dependency!
[Vote One Here, Complete my Survey....] Alok Gupta
visit me at http://www.thisisalok.tk "I Think Believe this Will Help" -
If this String is Object of CString then you simply use this Function CString strNum = "1234&567";
strNum.Replace("&","and");
[Vote One Here, Complete my Survey....] Alok Gupta
visit me at http://www.thisisalok.tk "I Think Believe this Will Help"i've checked the string class, and it also contains a replace member function, so essentially you can do the same thing that alok said for the CString class. anyway here's more definitions for the string class: http://www.cppreference.com/cppstring/[^]
-
i've checked the string class, and it also contains a replace member function, so essentially you can do the same thing that alok said for the CString class. anyway here's more definitions for the string class: http://www.cppreference.com/cppstring/[^]
ng kok chuan wrote: _anyway here's more definitions for the string class: http://www.cppreference.com/cppstring/\[^\]_ Looks Good Thanks
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta