Help plz....
i am trying to replace any whitespace in the following code with (*) i am not sure exactly how to implement the code...
string garbage;
garbage = "afahs grjr fkfk ";
Is there a thing in the standard string class that can search through the string or do I have to build my own function to do it.
Thanks for any ideas.
# 1 Re: Help plz....
i am trying to replace any whitespace in the following code with (*) i am not sure exactly how to implement the code...
string garbage;
garbage = "afahs grjr fkfk ";
Is there a thing in the standard string class that can search through the string or do I have to build my own function to do it.
Thanks for any ideas.
Look this up - _tcschr (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strchr.2c_.wcschr.2c_._mbschr.asp)
This is the code you need. :D
std::string garbage;
garbage = "afahs grjr fkfk ";
LPTSTR lpszPos = _tcschr (garbage.c_str (), ' ');
while (lpszPos)
{
*lpszPos = '*';
LPTSTR pszTemp = lpszPos;
lpszPos = _tcschr (pszTemp, ' ');
}
cout << garbage.c_str (); // Voila! It works!
# 3 Re: Help plz....
thanks for the help!!!!what exactly is happening in the body of that while loop??
You are welcome. :)
what exactly is happening in the body of that while loop??
Why don't you Debug to find out?
Besides, the post contains a link to _tcschr - why not read it?
# 4 Re: Help plz....
This is the code you need. :D
Nope...this is the code he actually needs... ;)
#include <string>
#include <iostream>
#include <algorithm>
int main()
{
std::string garbage("afahs grjr fkfk ");
std::replace(garbage.begin(), garbage.end(), ' ', '*');
std::cout << garbage << std::endl;
}
# 5 Re: Help plz....
Nope...this is the code he actually needs... ;)
I must reluctantly agree! :)
std::replace(garbage.begin(), garbage.end(), ' ', '*');You seem to be better at processing garbage than I! :D
Thanks, Andreas - 'coz I gained something too. :thumb:
Ciao,
Sid! :wave:
# 6 Re: Help plz....
You seem to be better at processing garbage than I! :D
Yeah...I am known for that... :D
Thanks, Andreas - 'coz I gained something too. :thumb:
You are welcome...