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

Thread: String

  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    String

    Hello

    I have this string:
    var Aussage = '{"48":["day":4]}{"49":[ "day":4]}';

    Whit indexOf i search the Position for the String 48
    var Suche = Aussage.indexOf("48");


    Now i want search the char { from the left of 48 and } from the right and delete all chars between.

    How can i do this??

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    You can do it with a regex without indexOf, like this:
    Code:
    var
        re=/\{(['"]?)48\1:[^}]*\}/g,
        sOrig='{"48":["day":4]}{"49":[ "day":4]}',
        sNew=sOrig.replace(re,'');
    However, this does not work if you have nested "}" that you don't want to match.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

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