HTML Escape Sequence versus \

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric

    HTML Escape Sequence versus \

    Hello,

    I'm having problems with the apostrophe character when building a
    Javascript array.

    I've come up with two different ways to fix the problem. I wondered
    if any one had any input as to which approach would be "best
    practices" and why.

    Approach 1:

    var aMyArray = new Array();
    aMyArray[aMyArray.length] = new Array('Person&# 39;s name.',
    '',
    'False',
    '',
    'True');

    Approach 2:

    var aMyArray = new Array();
    aMyArray[aMyArray.length] = new Array('Person\' s name.',
    '',
    'False',
    '',
    'True');

    Thanks,
    Eric
  • pr

    #2
    Re: HTML Escape Sequence versus \

    Eric wrote:
    I'm having problems with the apostrophe character when building a
    Javascript array.
    >
    I've come up with two different ways to fix the problem. I wondered
    if any one had any input as to which approach would be "best
    practices" and why.
    >
    Approach 1:
    >
    var aMyArray = new Array();
    aMyArray[aMyArray.length] = new Array('Person&# 39;s name.',
    Unless the programmer retains a table of ASCII codes in their head, this
    approach is going to be slightly more troublesome to maintain.

    [...]
    Approach 2:
    >
    var aMyArray = new Array();
    aMyArray[aMyArray.length] = new Array('Person\' s name.',
    This is more normal.

    Simplest of all is:

    aMyArray[aMyArray.length] = new Array("Person's name.", ...

    Comment

    • pr

      #3
      Re: HTML Escape Sequence versus \

      pr wrote:
      Eric wrote:
      >aMyArray[aMyArray.length] = new Array('Person&# 39;s name.',
      >
      Unless the programmer retains a table of ASCII codes in their head, this
      approach is going to be slightly more troublesome to maintain.
      and I should have asked if you really meant ''' or '\u0027'.

      See
      <URL:http://developer.mozil la.org/en/docs/Core_JavaScript _1.5_Guide:Lite rals#Using_Spec ial_Characters_ in_Strings>
      <URL:http://www.w3.org/TR/html401/charset.html#h-5.3.1>

      Comment

      Working...