473,659 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a deHTMLize function for strings?

Code:

a = document.create TextNode("< 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 2266

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

a = document.create TextNode("< somestring >");

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


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

a = encode("< somestring >");

....and...

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

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.create TextNode("< somestring >");

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


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

a = encode("< somestring >");

...and...

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


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.create TextNode("< somestring >");

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


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

a = encode("< somestring >");

...and...

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


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(entitySt ring) {
return entityString.re place(/&(\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/rasterTriangleD OM.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.create TextNode("< somestring >");

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


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

a = encode("< somestring >");

...and...

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


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(entitySt ring) {
return entityString.re place(/&(\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
1821
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 inc.file switch ($technique) { case 'C': echo $charcoal; break;
5
2629
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* replace){ char* result; size_t l = strlen(source), r = strlen(replace), i; int number_of_replaces = 0; for(i = 0; i < l; i++){ if(source == search)
35
2446
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 time in considering this post, and for your comments. I wrote this function to simplify the task of combining strings using mixed sources. I often see the use of sprintf() which results in several lines of code, and more processing than really...
4
2778
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 dllCalls.addVer("string1", "string2") -this is how I created the method in the class. Now, in this static method that uses DllImport to read the dll, I need to move "string1" and "string2" into a structure called PARMS_DIRS since the only way the dll function can...
4
22989
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 them know they look like this: "{cf 5}" or "{cf 0}" or "{ul 1}" or "{ul 0}", etc. The commonality they have is that they are always 6 charters long and always begin and end with curly brackets. This all works great if the user is running the...
5
2224
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 list of songs and return any approximate matches along with a confidence factor. I have looked at edit distance, but that isn't a good choice for finding a short string in a longer one. I have also explored difflib.SequenceMatcher and...
17
11512
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 *array_string Thanks, -Kim
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 COMPACT COHERENT CODE THAT WORKS WITH STRINGS, IT ALL BEGINS TO MAKE SINCE*/ /* The basics of C++ are Classes, that build Types. Which are used to create quick and dirty routines in the smallest possible space. The Classes & Routines uses the...
0
8330
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7355
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2749
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.