Problem with CString::Replace ( LPCTSTR lpszOld, LPCTSTR lpszNew );
-
I have a CString type variable with a large HTML file in it. When I attempt to replace all occurrances of a character with another characer, it works fine, however, if I attempt to replace a string ("= ") with another string ("="), it appears to get stuck in some endless loop somewhere. I have left it running for hours, and it is still stuck at the same replace statement. Is there something I'm missing?
-
I have a CString type variable with a large HTML file in it. When I attempt to replace all occurrances of a character with another characer, it works fine, however, if I attempt to replace a string ("= ") with another string ("="), it appears to get stuck in some endless loop somewhere. I have left it running for hours, and it is still stuck at the same replace statement. Is there something I'm missing?
-
Whats your code? Mazy "The more I search, the more my need For you, The more I bless, the more I bleed For you."The Outlaw Torn-Metallica
It's not a very elegant method, but the code is: void CParser::StandardiseHTML ( CString* HTMLfile ) { HTMLfile->Replace ("@", "@"); HTMLfile->Replace ('\n', ' '); HTMLfile->Replace ('\t', ' '); HTMLfile->Replace (" ", " "); while ( HTMLfile->Replace (" ", " ") != 0 ); HTMLfile->Replace (" =", "="); HTMLfile->Replace ("= ", "="); HTMLfile->MakeUpper (); } It manages to get into trouble with the statement HTMLfile->Replace (" ", " ");
-
It's not a very elegant method, but the code is: void CParser::StandardiseHTML ( CString* HTMLfile ) { HTMLfile->Replace ("@", "@"); HTMLfile->Replace ('\n', ' '); HTMLfile->Replace ('\t', ' '); HTMLfile->Replace (" ", " "); while ( HTMLfile->Replace (" ", " ") != 0 ); HTMLfile->Replace (" =", "="); HTMLfile->Replace ("= ", "="); HTMLfile->MakeUpper (); } It manages to get into trouble with the statement HTMLfile->Replace (" ", " ");
-
What??? No, where it says HTMLfile->Replace (" ", " "); the first string is actually a non-braking space character - In the while loop, it's meant to have two spaces between the first seyt of inverted commas, and one in the second set.
Is it possible the first character is actually a space just like the second? That would cause an infinite loop, as each call to replace will find the same character and replace it with itself.