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.
[348 byte] By [titanswimmer03] at [2007-11-19 7:30:13]
# 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!
Siddhartha at 2007-11-9 0:42:35 >
# 2 Re: Help plz....
thanks for the help!!!!what exactly is happening in the body of that while loop??
titanswimmer03 at 2007-11-9 0:43:35 >
# 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?
Siddhartha at 2007-11-9 0:44:34 >
# 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;
}
Andreas Masur at 2007-11-9 0:45:33 >
# 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:
Siddhartha at 2007-11-9 0:46:32 >
# 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...
Andreas Masur at 2007-11-9 0:47:36 >