View Full Version : how to use the strip facility??

03-11-2004, 03:39 PM
How do i use the strip facility in javascript. I have an cell ID's (cell1 / cell2 / cell3 etc) and i want to strip the word "cell" and store the number in a variable.

With this i want to do calulations and my website will validate to XHTML Strict

fanx in advance

03-11-2004, 06:11 PM
Since I don't know what your variables are called, I'm going to assume they're in fact called cell1, cell2, ...

I'm not going to use strip, I think charAt is better in this case. substring could also be used...

var cell_id1 = cell1.id;
var num1 = parseInt(cell_id1.charAt(4));

Now num1 should hold 1. parseInt will convert the string '1' to the integer 1.

Hope that helps,