for example
there is a string "the box is blue"
how to change the string into "theboxisblue"
or there is a string "the?box?is?blue"
how to change the string into "theboxisblue"
Printable View
for example
there is a string "the box is blue"
how to change the string into "theboxisblue"
or there is a string "the?box?is?blue"
how to change the string into "theboxisblue"
When you say "string", you need to specify exactly what type of string you are talking about.
std::string?
an array of char?
CString?
Regards,
Paul McKenzie
You can use std::remove() algorithm to remove blanks
(or some other character) from a NULL terminated c-style
string, or from a std::string as shown below. For std::string
you need to call its erase() member function also.
Code:#include <algorithm> // for std::remove
#include <string> // for std::string
int main()
{
char str1[] = "the box is blue";
std::remove(str1,str1+strlen(str1)+1,' ');
std::string str2 = "the?box?is?blue";
str2.erase(std::remove(str2.begin(),str2.end(),'?') , str2.end() );
return 0;
}
If u are using CString then following code will help u
CString ss = "the?box?is?blue";
ss.Replace("?","");
In this "Replace" function the
1st parameter is "What u want to replace in the string and
2nd parameter is "With which u want to replace".
if the string is like
ss = "the box is blue";
then replace will be like
ss.Replace(" ","");