473,505 Members | 14,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a deHTMLize function for strings?

Code:

a = document.createTextNode("< somestring >");

....will transform < into &lt; and > into &gt;

When I want to read that node later, I can only get it back in
this form: "&lt; somestring &gt;"

Is there a function that transforms such strings containing
HTML codes back to normal strings? Something like:

string deHTMLize (string);

What I need is to quote and send a part of the document when
user clicks a button, so I need the string without codes.
Apr 19 '06 #1
5 2254

"test" <te**@test.test> wrote in message
news:10******************************@40tude.net.. .
Code:

a = document.createTextNode("< somestring >");

...will transform < into &lt; and > into &gt;


I think what you want is encode() and decode()...

a = encode("< somestring >");

....and...

a = decode("&lt;%20somestring%20&gt;");

Apr 19 '06 #2
On Wed, 19 Apr 2006 10:43:51 GMT, Noozer wrote:
"test" <te**@test.test> wrote in message
news:10******************************@40tude.net.. .
Code:

a = document.createTextNode("< somestring >");

...will transform < into &lt; and > into &gt;


I think what you want is encode() and decode()...

a = encode("< somestring >");

...and...

a = decode("&lt;%20somestring%20&gt;");


But, there are no such functions in JavaScript? I can't find
them, and I get errors in javascript:

"encode is not defined"
Apr 19 '06 #3
test <te**@test.test> writes:
On Wed, 19 Apr 2006 10:43:51 GMT, Noozer wrote:
"test" <te**@test.test> wrote in message
news:10******************************@40tude.net.. .
Code:

a = document.createTextNode("< somestring >");

...will transform < into &lt; and > into &gt;


I think what you want is encode() and decode()...

a = encode("< somestring >");

...and...

a = decode("&lt;%20somestring%20&gt;");


But, there are no such functions in JavaScript? I can't find
them, and I get errors in javascript:

"encode is not defined"


I don't know them either.

But you can make a decoder relatively easily:
---
var conversionMap = {
"amp" : "&",
"lt" : "<",
"gt" : ">",
"apos" : "'",
"quot" : '"'
}

function decode(entityString) {
return entityString.replace(/&(\w+);/g, function(m,g) {
return conversionMap[g]||m;
});
}
---
It requires a modern browser that accepts a function as second a
argument to replace.

If your string contains URL-escapes (%xx), you can first decode
these using the global "unescape" function (or after, depending
on what you want to unescape first).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Apr 19 '06 #4

"test" <te**@test.test> wrote in message
news:1a******************************@40tude.net.. .
On Wed, 19 Apr 2006 10:43:51 GMT, Noozer wrote:
"test" <te**@test.test> wrote in message
news:10******************************@40tude.net.. .
Code:

a = document.createTextNode("< somestring >");

...will transform < into &lt; and > into &gt;


I think what you want is encode() and decode()...

a = encode("< somestring >");

...and...

a = decode("&lt;%20somestring%20&gt;");


But, there are no such functions in JavaScript? I can't find
them, and I get errors in javascript:


Doh... Sorry. It was too early.

I meant escape() and unescape() ...
Apr 19 '06 #5
On Wed, 19 Apr 2006 18:36:23 +0200, Lasse Reichstein Nielsen
wrote:
But you can make a decoder relatively easily:
---
var conversionMap = {
"amp" : "&",
"lt" : "<",
"gt" : ">",
"apos" : "'",
"quot" : '"'
}

function decode(entityString) {
return entityString.replace(/&(\w+);/g, function(m,g) {
return conversionMap[g]||m;
});
}
---
It requires a modern browser that accepts a function as second a
argument to replace.


Thanks much, works like a charm on Firefox 1.5.0.1.
Apr 20 '06 #6

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

Similar topics

9
1811
by: bettina | last post by:
I have the following piece of code (symplified) require("lang.{$lang}.inc.php"); // I include the inc. files .... function decodify($technique) { // functions that give me back the value in...
5
2618
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char*...
35
2409
by: michael.casey | last post by:
The purpose of this post is to obtain the communities opinion of the usefulness, efficiency, and most importantly the correctness of this small piece of code. I thank everyone in advance for your...
4
2768
by: Angel | last post by:
I'm trying to call a DLL function that receives as parameter a user-defined structure created by the company that made the dll. When I call the function from my main form, I call...
4
22979
by: Lauren Wilson | last post by:
Hi folks, We have a need to replace sub strings in certain message text. We use the Office Assistant to display help and often use the imbedded formatting commands. Those of you who have used...
5
2215
by: BBands | last post by:
I'd like to see if a string exists, even approximately, in another. For example if "black" exists in "blakbird" or if "beatles" exists in "beatlemania". The application is to look though a long...
17
11496
by: kleary00 | last post by:
Hi, I am writing a function that needs to return an array of strings and I am having some trouble getting it right. I need some help. Here is what I consider an array of 100 strings: char...
4
455
by: CoreyWhite | last post by:
/* WORKING WITH STRINGS IN C++ IS THE BEST WAY TO LEARN THE LANGUAGE AND TRANSITION FROM C. C++ HAS MANY NEW FEATURES THAT WORK TOGETHER AND WHEN YOU SEE THEM DOING THE IMPOSSIBLE AND MAKING...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.