Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with CString::Replace ( LPCTSTR lpszOld, LPCTSTR lpszNew );

Problem with CString::Replace ( LPCTSTR lpszOld, LPCTSTR lpszNew );

Scheduled Pinned Locked Moved C / C++ / MFC
helphtmlquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Munkijo
    wrote on last edited by
    #1

    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?

    M 1 Reply Last reply
    0
    • M Munkijo

      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?

      M Offline
      M Offline
      Mazdak
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • M Mazdak

        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

        M Offline
        M Offline
        Munkijo
        wrote on last edited by
        #3

        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 (" ", " ");

        M 1 Reply Last reply
        0
        • M Munkijo

          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 (" ", " ");

          M Offline
          M Offline
          Munkijo
          wrote on last edited by
          #4

          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.

          B 1 Reply Last reply
          0
          • M Munkijo

            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.

            B Offline
            B Offline
            Bill Wilson
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups