Results 1 to 4 of 4

Thread: Problem with string replace

  1. #1
    Join Date
    Jul 2008
    Posts
    22
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Problem with string replace

    Hi,

    I have a problem in that I have values coming from a database which contain   instead of a normal space. I'm trying to replace all instances of this with a normal space. They are outputted in my javascript within a new Option function, so I'm not sure how to go about doing a string replace on this. Any help would be much appreciated. Here is my code:

    Code:
    if (chosen4 == "17") {
      selbox4.options[selbox4.options.length] = new
    Option('Only 34.99 EUR','link1.html');
    }

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The way it looks there, it's hard coded, just change it to a regular space.

    But to answer your question about a string. Say your string is in a variable named str:

    Code:
    str = str.replace(/\xa0|(\ )/g, ' ');
    will replace all nbsp characters as well as all nbsp entities in it with space (hex 20) characters. The net result will be that any run of one or more nbsp's will then be rendered in HTML as a single wrap capable space.
    Last edited by jscheuer1; 03-07-2009 at 12:32 AM. Reason: fix typo pointed out by Master_script_maker
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    John i believe there is a typo in your script:
    Code:
    str = str.replace(/\xa0|(\&npbs;)/g, ' ');
    str = str.replace(/\xa0|(\ )/g, ' ');
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  4. The Following User Says Thank You to Master_script_maker For This Useful Post:

    jscheuer1 (03-07-2009)

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Master_script_maker View Post
    John i believe there is a typo in your script:
    Code:
    str = str.replace(/\xa0|(\&npbs;)/g, ' ');
    str = str.replace(/\xa0|(\ )/g, ' ');
    That's right, shows you what too much multitasking can do.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •