Web Analytics Made Easy -
StatCounter Split function creating a random comma - CodingForum

Announcement

Collapse
No announcement yet.

Split function creating a random comma

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolved Split function creating a random comma

    Hi there!

    I'm trying to retrieve the integer value in the string: #10
    So I'm using the JS Split function

    Code:
    <script type="text/javascript">
    
    var str="#10";
    document.write(str.split("#"));
    
    </script>
    Is the code I'm using, but I keep getting a comma before my result..
    in this case, my result is ",10"

    What should I do?
    Thanks!

    Kind Regards
    Matthew

    P.S. I know that it's an array, but is there still anyway for me to get rid of the comma?
    Last edited by GreenFanta; Aug 18, 2011, 06:34 AM.

  • #2
    document.write(str.split("#")[1]);

    Comment


    • #3
      Ah, thank you, I don't know why I didn't think of that...

      Comment


      • #4
        Another way to strip the first character is

        Code:
        var str="#10";
        str = str.substring(1);
        document.write(str);
        Or convert to a number using

        Code:
        str = Number(str.substring(1));

        All the code given in this post has been tested and is intended to address the question asked.
        Unless stated otherwise it is not just a demonstration.

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎