PDA

View Full Version : Changing a character into an integer in a string


noviceNate
10-10-2002, 03:58 PM
Not sure this is possible. I have a URL with numbes in it. I know the position within the string of the URL that the numbers will be at every time. I want to be able to first determine what the number is at a certain position, and then change that number into an actual number.

Such as...

http://www.mysite.com/folder/page01.htm

is the initial URL. My script would scan the string and at the 34 and 35 position of the string (I think), it would see that 0 and 1 are at those positions. SO, what then happens is it changes the 0 and 1 characters into 0 and 1 integers, so that I can then use them in math functions.

Does this make sense? I would appreciate some help. Thanks

beetle
10-10-2002, 04:08 PM
Sure...var myUrl = "http://www.mysite.com/folder/page01.htm
";
var nums = myUrl.substring(33,34);
var int1 = parseInt(nums.charAt(0));
var int2 = parseInt(nums.charAt(1));This *should* work. However, if you know that the 01 in page01.htm are going to be the only numbers in the URL, then you can use this in place of the substring line...var nums = myUrl.replace(/\D/g,"");

ASAAKI
10-10-2002, 04:08 PM
if u've got a variable holding any number as a character, u use parseInt(that_variable) to make it an operatable number.

i see beetle happened to hit the Submit Reply button before me

noviceNate
10-10-2002, 04:22 PM
Thank you, that seems to be what I needed!