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

Thread: slashes

  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts

    slashes

    how do I add slash "\" and backslash "/" to a string?

    Thanks

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    The backslash is the escape character, so you'll have to escape it, but the forward slash you should have no problems with:
    Code:
    var str = "this is a backslash \\, this is a forward slash /";
    alert(str);

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    You can add a forward slash as normal but a back slash is escaped with another backslash


    <script type="text/javascript">
    <!--
    str1="hello/world"
    alert(str1)

    str2="hello\\world"
    alert(str2)
    -->
    </script>
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.


  •  

    Posting Permissions

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