CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Mar 2008
    Posts
    3

    Resolved C++ Replacing HTML Character Entities [RESOLVED]

    Hello, this is my first post on this forum, hope it works out

    I'm trying to do HTML entity decoding in C++, couldn't find any existing text out there to help out. Hows this look? It works on a small scale, but with lots of text it tends to stumble, even lock some times. Any ideas on performance here, or what I might be doing wrong?

    Thanks in advance!

    Code:
    string htmlEntitiesDecode (string str) {
    
    	string subs[] = {
    		""", """,
    		"'", "'",
    		"&", "&",
    		"<", "&lt;",
    		">", "&gt;"
    	};
    	
    	string reps[] = {
    		"\"", "\"",
    		"'", "'",
    		"&", "&",
    		"<", "<",
    		">", ">"
    	};
    	
    	size_t found;
    	for(int j = 0; j <= 10; j++) {
    		do {
    			found = str.rfind(subs[j]);
    	  	if (found != string::npos)
        		str.replace (found,subs[j].length(),reps[j]);
        } while (found != string::npos);
      }
      return str;
    }
    Last edited by jmhobbs; March 19th, 2008 at 03:51 PM. Reason: Problem resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured