Problems with String.replace

Hey folks,

i tried to manipulate my strings a bit but have a few problems after being abstinent for a few years in things like coding.

My Line is:
1
2
3
4
5
6
7
8
str_Col = str_Line.substr(i_SubstrStartPos, (i_SeperatorPos - i_SubstrStartPos));
i_Temp = 0;
while (	(i_Temp = str_Col.find(" ",i_Temp)) != string::npos) 
     str_Col.replace(i_Temp,1,"");
printf("%s\n", str_Col.c_str());
while (	(i_Temp = str_Col.find("\"",i_Temp)) != string::npos) 
     str_Col.replace(i_Temp,1,"");
printf("%s\n", str_Col.c_str());


if i delete those lines with printf, my string is being corrupted. An Example:
My initial string is
" YEHA"
after manipulating it, i want to have
YEHA
without printf-lines i will have
YEHA""

It seems, that the length of string will not be changed while replacing in that way. I tried to use erase, but this won't work either - were is my mistake?

Best Regards
Have you tried using string::erase instead of string::replace?

Also, and I could be incorrect here, but I believe it would be best to use single quotes (' ') instead of (" ") when indicating a single character.
line 6 will never be executed since 'i_Temp' is always 'string::npos' at that moment. write i_Temp = 0; before line 6
@Snarky
with erase i have a similar problem

@coder777
this is right. i fixed it different
 
(i_Temp = str_Col.find(":",0)

i think this will work also.

Someone got an idea?
Topic archived. No new replies allowed.