Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Splitting javascript string

Options
  • 16-03-2006 10:27pm
    #1
    Closed Accounts Posts: 201 ✭✭


    var a="C:\Documents\C\S"; 
    var ar=a.split("\\"); 
    alert(ar[0]+" "+ar[1]);
    

    Output : C:DocumentsCS undefined

    It should be "C: Documents" instead whats wrong with the code????
    Any ideas??


Comments

  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    what do you get if you change the path to
    var a="C:\\Documents\\C\\S";


  • Closed Accounts Posts: 201 ✭✭bazcaz


    Fixed cheers for help anyway


  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    what was it?


  • Closed Accounts Posts: 201 ✭✭bazcaz


    I was getting a file path like C:\Documents and Settings\User\...... and reading it into a variable and I was trying to work out a way in which to split it by \ so as a test I had tried that code above where I explicitly created the string C:\Document\C\D but the difference is that the file path in the first instance must have been saved in the variable as C:\\Documents and Settings\\User so my split line would work fine on that which is what I wanted but in the other case I had explicitly created the string with only a single \ separator so the code doesnt work there.

    Do you get me??


  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    yep, thats what I was getting at with my first post.

    If its a generated path it will already be escaped.
    Whats generating the path?

    (Note that you can use unix style paths ("/") and they dont need to be escaped and will work on Unix and Windows)


  • Advertisement
  • Closed Accounts Posts: 201 ✭✭bazcaz


    A bit of framework code for an extension to Mozilla Thunderbird


Advertisement