473,378 Members | 1,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to encode/decode a HTML using C++??

Hi,

Is there a way to encode/decode HTML using C++??

Thanks,
Sarada.

Feb 16 '06 #1
7 16538
Be more specific.

In several application development softwares there are readymade
components which can interpret HTML.

Feb 16 '06 #2
sa*****@gmail.com wrote:
Hi,

Is there a way to encode/decode HTML using C++??


Encode and decode into what? Where is the html/source coming from?
Where should it go to?

Take a look at:

std::string;

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Feb 16 '06 #3
* sa*****@gmail.com:

Is there a way to encode/decode HTML using C++??


No way. Those web-browser said to implemented in C or C++? Well, it's
just a sham, they're all implemented in JavaScript.

Hth.,

- Alf
PS: HTML is just plain text, so what is the problem?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 16 '06 #4
I have a C++ function which returns a string and later this string is
used by ASP for display. If I use HTMLEncode in ASP this solves my
problem. But there are some cases where the string output is an image
tag and I don't want HTMLEncode to show the tag as it is. I am trying
to remove the HTMLEncode in ASP and try to encode the string in C++
before sending it to ASP. Please let me know if this is clear or any
thoughts are welcome.
Thanks

Feb 16 '06 #5
Encoding it is simple. Decoding takes a slightly longer function, doing
the same thing in reverse. Note that this won't work on EBCDIC based
machines (silly IBM).

To selectively encode different tags, parse the input string and output
the code depending on what you want.

Assuming you don't have an operating system or library function to do
the work for you, it is:

string EncodeHtml(const wstring& html)
{
ostringstream result;
wstring::const_iterator i;
for (i = html.begin(); i != html.end(); ++i)
{
if (*i >= 128)
result << "&#" << static_cast<int>(*i) << ";";
else if (*i == '<')
result << "&lt;";
else if (*i == '>')
result << "&gt;";
else if (*i == '&')
result << "&amp;";
else if (*i == '"')
result << "&quot;";
else
result << static_cast<char>(*i); // Copy untranslated
}
return result.str();
}

Feb 16 '06 #6
Thanks for your help!

Feb 16 '06 #7
Hmm, I don't know about your newsreader, but my posted code is showing
up wrong on google groups, despite "Preview" working.
i.e. "ampersand L T semicolon" ("&lt;") is showing up as "<" which
defeats the point really. The appropriate strings (using string literal
concatenation) are:
"&" "lt;"
"&" "gt;"
"&" "amp;"
"&" "quot;"
I hope the mangling was just at the client end, but still it could be
annoying if you are viewing newsgroups using a web browser. Oh well.

Feb 17 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: fowlertrainer | last post by:
Hi ! I'm hungarian, we use special characters like: á - a' õ -o" etc. I want to encode this characters to in config file I see these characters as \nnn format.
3
by: Ricky | last post by:
Is there any way to detect if a field has been encoded before I decode a field.
4
by: Newbie | last post by:
How would I modify this form to encode *all* the characters in the 'source' textarea to the '%xx' format & place result code into the 'output' textarea? (cross browser compatable) Any help is...
1
by: AR | last post by:
I would like to know more about the Encode/Decode feature available within MS Access. This is what I have read from Microsoft Office OnLine: "The simplest method of protection is to encode the...
4
by: Darrel | last post by:
How does HTML.encode work? I'm trying to save text in a hidden form field into a SQL DB. The tedt is HTML (from a WYSIWYG editor...X-standard). One problem I have is that stray apostrophe's in...
7
by: jtfaulk | last post by:
I need to encode some information on the server side using ASP.NET with C#; sending via HTTP to a client side application, that needs to be decoded in an MFC C++ application. I'm not sure if I...
6
by: 7stud | last post by:
s1 = "hello" s2 = s1.encode("utf-8") s1 = "an accented 'e': \xc3\xa9" s2 = s1.encode("utf-8") The last line produces the error: --- Traceback (most recent call last):
4
by: J Peyret | last post by:
Well, as usual I am confused by unicode encoding errors. I have a string with problematic characters in it which I'd like to put into a postgresql table. That results in a postgresql error so I...
1
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.