|
-
July 9th, 2003, 08:05 PM
#1
how to delete ' ' in the string
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"
-
July 9th, 2003, 08:54 PM
#2
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
-
July 9th, 2003, 10:00 PM
#3
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;
}
-
July 10th, 2003, 07:17 AM
#4
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(" ","");
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|