...

View Full Version : Resolved Split function creating a random comma



GreenFanta
08-18-2011, 12:25 PM
Hi there!

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



<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?

DaveyErwin
08-18-2011, 12:32 PM
document.write(str.split("#")[1]);

GreenFanta
08-18-2011, 12:33 PM
Ah, thank you, I don't know why I didn't think of that... :thumbsup:

Philip M
08-18-2011, 01:29 PM
Another way to strip the first character is


var str="#10";
str = str.substring(1);
document.write(str);

Or convert to a number using


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum