Replacing HTML entities in HTTP source

117 Views Asked by At

I use WinHTTP to GET resource from a URL which returns the source with HTML entities. But I require to make the text readable by replacing them with normal special characters. Would there be an option in WinHTTP or what would be the fastest way to do it?

1

There are 1 best solutions below

0
On

Iterate through the returned HTML, consuming and emitting characters one at a time. When you encounter any of the given characters that need to be replaced, just discard the consumed character and emit it's equivalent replacement instead. This can be done efficiently with an array:

const char *replacements[256] = {
    ['<'] = "&lt;",
    ['>'] = "&gt;"
    /* etc */
};