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 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getting part of a value

    if i have a value var1 that is something like "C:\path\filename.jpg"
    how can I only display filename.jpg?
    pretty much look till first "\" from the right.
    any help would be appreciated.

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Code:
    <html>
    
    <head>
    <script language="javascript">
    
    fullpath="C:\\path\\filename.jpg";
    
    function showfile(currpath){
      slashpos=currpath.lastIndexOf("\\");
      filename=currpath.substring(slashpos+1, currpath.length);
      alert(filename);
    }
    </script>
    </head>
    
    <body onload="showfile(fullpath);">
    
    </body>
    
    </html>
    edit: I forgot to escape the backslashes in the fullpath variable.
    Last edited by arnyinc; 01-17-2006 at 09:14 PM.

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you thank you thank you


  •  

    Posting Permissions

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