JavaScript's Character Escaping Functions

G

Gene Wirchenko

Dear JavaScripters:

There are a number of functions for escaping various characters
and de-escaping them:
Escape Function Unescape Function
--------------- -----------------
escape() unescape()
encodeURI() decodeURI()
encodeURIComponent() decodeURIComponent()
There may be others that I am unaware of.

What I am definitely unaware of is when to use them. I have not
seen any material on that other than vague (to me) sentences. They
seem to assume that people already know what they are doing with them.

Between them and HTML's "&something;", I really could use a good
grounding in the area.

Pointers please?

Sincerely,

Gene Wirchenko
 
T

Tim Streater

Gene Wirchenko said:
Dear JavaScripters:

There are a number of functions for escaping various characters
and de-escaping them:
Escape Function Unescape Function
--------------- -----------------
escape() unescape()
encodeURI() decodeURI()
encodeURIComponent() decodeURIComponent()
There may be others that I am unaware of.

What I am definitely unaware of is when to use them. I have not
seen any material on that other than vague (to me) sentences. They
seem to assume that people already know what they are doing with them.

Between them and HTML's "&something;", I really could use a good
grounding in the area.

Pointers please?

<furtle, furtle>

Ah yes, here we are: pp 482-483 of JavaScript Bible 7th Edition seem to
cover it.

What's that? You don't have any JavaScript books? Why not?
 
G

Gene Wirchenko

[snip]
Pointers please?

<furtle, furtle>

Ah yes, here we are: pp 482-483 of JavaScript Bible 7th Edition seem to
cover it.

What's that? You don't have any JavaScript books? Why not?

I do have JavaScript books including one that is pretty good, but
it does not have all the detail I could wish for. As for additional
books, well, I have already asked about that. Take a look at the FAQ:

"3.1 What books are recommended for javascript?

Most javascript books have been found to contain so many technical
errors that consensus recommendations have not emerged from the group.

The following books have been considered to have value by some
individuals on c.l.js. The reviews of these books are provided:"

There are links to discussion on the *two* titles, and said
discussions are not encouraging for a ptoential purchaser.

If you have a better answer, how about submitting a change to FAQ
question 3.1?

Sincerely,

Gene Wirchenko
 
M

Michael Haufe (TNO)

Dear JavaScripters:

     There are a number of functions for escaping various characters
and de-escaping them:
          Escape Function          Unescape Function
          ---------------          -----------------
          escape()                 unescape()
          encodeURI()              decodeURI()
          encodeURIComponent()     decodeURIComponent()
There may be others that I am unaware of.

     What I am definitely unaware of is when to use them.  I havenot
seen any material on that other than vague (to me) sentences.  They
seem to assume that people already know what they are doing with them.

     Between them and HTML's "&something;", I really could use a good
grounding in the area.

     Pointers please?

You can look at MDN's documentation:

https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#escape_and_unescape_Functions
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURI
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURIComponent
 
J

Jukka K. Korpela

If you have a better answer, how about submitting a change to FAQ
question 3.1?

Why would anyone submit a change proposal when there is no FAQ maintainer?
 
T

Tim Streater

Gene Wirchenko said:
[snip]
Pointers please?

<furtle, furtle>

Ah yes, here we are: pp 482-483 of JavaScript Bible 7th Edition seem to
cover it.

What's that? You don't have any JavaScript books? Why not?

I do have JavaScript books including one that is pretty good, but
it does not have all the detail I could wish for. As for additional
books, well, I have already asked about that. Take a look at the FAQ:

"3.1 What books are recommended for javascript?

Most javascript books have been found to contain so many technical
errors that consensus recommendations have not emerged from the group.

The following books have been considered to have value by some
individuals on c.l.js. The reviews of these books are provided:"

There are links to discussion on the *two* titles, and said
discussions are not encouraging for a ptoential purchaser.

If you have a better answer, how about submitting a change to FAQ
question 3.1?

:)

Well, I don't have a *better* answer, only my own opinion. See also my
other post.
 
D

Denis McMahon

There are a number of functions for escaping various characters
and de-escaping them:
....
Between them and HTML's "&something;", I really could use a good
grounding in the area.

If I need to use any sort of character escaping, I tend to first work out
exactly what I'm trying to escape and why, and then read the descriptions
of each function to determine which one is best suited to my requirement.

Rgds

Denis McMahon
 
D

Dr J R Stockton

In comp.lang.javascript message <nk4qf7ti2bbod0k5flbs0bbm880dpdvv35@4ax.
There are a number of functions for escaping various characters
and de-escaping them:
Escape Function Unescape Function
--------------- -----------------
escape() unescape()
encodeURI() decodeURI()
encodeURIComponent() decodeURIComponent()
There may be others that I am unaware of.

What I am definitely unaware of is when to use them. I have not
seen any material on that other than vague (to me) sentences. They
seem to assume that people already know what they are doing with them.

Between them and HTML's "&something;", I really could use a good
grounding in the area.

Pointers please?

ECMA 5.1 section 15.3 gives full detail for the URI ones. The document
should be findable via the FAQ, and downloadable at an acceptable cost.
You need it. Section B.2 explains the escapes.

I doubt whether you want any of them.

You probably want "Table 4 — String Single Character Escape Sequences"
in section 7.8.4.

You might also need section "7.8.5 Regular Expression Literals", and
section 15.10 if you don't know RegExps from other languages.

For the HTML, read Wikipedia "Character entity reference" and its links
including "List of XML and HTML character entity references". For
characters outside that range, see <http://en.wikipedia.org/wiki/List_of
_Unicode_characters> and the definitive <http://unicode.org/charts/chari
ndex.html>.

If you discover that any of those cannot be found by links from pages on
my Web site, RSVP - should be in the js- and www- pages.

If all else fails, read the manual.
 
G

Gene Wirchenko

If I need to use any sort of character escaping, I tend to first work out
exactly what I'm trying to escape and why, and then read the descriptions
of each function to determine which one is best suited to my requirement.

Of course, it helps to know exactly what the functions are and
what they do. Could that possibly be why I asked my question in the
first place?

Sincerely,

Gene Wirchenko
 
D

Dr J R Stockton

In comp.lang.javascript message <5f30g75q1h82jif9r1fcajc3gqffjvguhp@4ax.
Of course, it helps to know exactly what the functions are and
what they do. Could that possibly be why I asked my question in the
first place?

But the ECMA standard tells you exactly that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top