Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript trouble string function

    Have a nice day ! I have this folowing code and it won't run? I can't understand why, pls help me solve this thanks.

    I have a string, and I need to use match (to retrieve what i need) and use substr or replace (to replace my signs)

    var orgstring = "!u!http://annt/newspage/media/stories/jerryc_canonrock.wmv!u!!w!300!w!!h!60!h!!s1!false!s1!!s2!true!s2!!s3!false!s3!";
    var urlthis = orgstring;

    urlthis = urlthis.match(/!u!(.*?)!u!/g);
    urlthis = urlthis.replace("!u!",'');


    I tried to use match and replace alone -> it runs. But use both -> it did'nt word.
    What can I do ? pls

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    urlthis.match(/!u!(.*?)!u!/g);

    returns an array of strings, so when you do this:

    urlthis = urlthis.match(/!u!(.*?)!u!/g);

    urlthis is now an array, which doesn't have a replace function, so this:

    urlthis = urlthis.replace("!u!",'');

    breaks.

    There's no reason to do match before replace. Try just using replace.


  •  

    Posting Permissions

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