Click to See Complete Forum and Search --> : conversion...
rincewind2
09-11-2003, 05:41 AM
I'm a bit new to all this with javascript..
How do I convert a char to an int?
and how do i convert an int to a string?
Thankfull for reply,
rincewind2
09-11-2003, 06:43 AM
Okay. Lets try this with another question=):
what im trying to do is to break out a value from a string.
if i got a string like:
var dbreply='#ID#="11"';
and whant to convert the 11 to a integer value?!
the 11 value can variate..
How do I do this?
regardz,
*Desperate*
=)
therealphil
09-11-2003, 06:49 AM
var dbreply='#ID#="11"'; //original string
var i = dbreply.indexOf("\""); // finds " in the string
var int = i.substring(1,3); // takes out whatever is between the " marks
alert("My Integer ="+ int);
This assumes that your integer is always a 2 digits in length
Not sure if it'll work, only just knocked it up quickly
rincewind2
09-11-2003, 06:56 AM
I thought the
var i=dbreply.indexOf("\""); only returned the index of the matching sting (in this case the " character).
So i should only containt a integer that should countain the index to the " character?
therealphil
09-11-2003, 07:07 AM
Hmmm yep yep
var startPos = dbreply.indexOf("\"");
var endPos = dbreply.indexOf("\"")+3;
var int = dbreply.substring(startPos,endPos);
Try that? I'm very new to JScript still so I'm really just putting down what comes to mind.
therealphil
09-11-2003, 07:08 AM
Sorry,
var endPos = dbreply.indexOf("\"")+3;
should be..
var endPos = dbreply.indexOf("\"")+2;
still assuming a 2-digit number