SimonSmith
Member
void a = "123"
void b = a + 100
The result is 123100,I want it returns 223,how to handle this ?
void b = a + 100
The result is 123100,I want it returns 223,how to handle this ?
void main()
{
char a = "123";
int b = string2int(a)+100;
settextobj(1, 140 , 90 , 3, 99999999999999, "output "+b);
}
char string2int(char string)
{//msmalik681 convert string to intiger needs extra fuction "merge".
int i;
char tempCa;
char tempCb;
int tempI;
for(i=0;i<strlength(string);i++)
{
if(i==0)
{
tempCb = strleft(string,i+1);
} else {
tempCa = strleft(string,i+1);
tempCb = strright(tempCa,i);
}
tempI = NULL();
if(tempCb=="9"){
tempI = 9;
} else if(tempCb=="8"){
tempI = 8;
} else if(tempCb=="7"){
tempI = 7;
} else if(tempCb=="6"){
tempI = 6;
} else if(tempCb=="5"){
tempI = 5;
} else if(tempCb=="4"){
tempI = 4;
} else if(tempCb=="3"){
tempI = 3;
} else if(tempCb=="2"){
tempI = 2;
} else if(tempCb=="1"){
tempI = 1;
} else if(tempCb=="0"){
tempI = 0;
}
if(tempI != NULL())
{
setlocalvar("string."+i+"",tempI);
}
}
tempI = NULL();
for(i=0;i<strlength(string);i++)
{
if(getlocalvar("string."+i+"") != NULL())
{
if(tempI==NULL())
{
tempI = getlocalvar("string."+i+"");
continue;
} else {
tempI = merge(tempI,getlocalvar("string."+i+""));
}
}
}
return tempI;
}
int merge(int int1, int int2)
{//msmalik681 merge 2 intiger values togeather.
if(int1 != NULL() && int2 != NULL())
{
int int2_copy = int2;
do
{
int1 *= 10;
int2_copy /= 10;
} while (int2_copy);
return int1 + int2;
} else if(int1 != NULL()) {
return int1;
} else if(int2 != NULL()){
return int2;
} else { return 0;}
}
Thank you .Damon Caskey said:Once a string is a string there's no going back. You need to rework the logic elsewhere instead. What are you trying to do?
DC
For example, my idea is like this:msmalik681 said:SimonSmith DC was asking how you got a int stuck in a char so a better solution could be devised or where you just asking as a general question ?