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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Splitting javascript string

  • 16-03-2006 9: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, Registered Users 2 Posts: 27,370 ✭✭✭✭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, Registered Users 2 Posts: 27,370 ✭✭✭✭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, Registered Users 2 Posts: 27,370 ✭✭✭✭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