SimonSmith said:
for example:
void a="1";
void b=2;
void c=a+b;
log(c+"\n");
The result I want is 3, not "12".
Thanks.
Edit:
And how to judge a string a valid number?
Yes, you can do a script for this function.
1st you have to do a switch block where you associate a string num to an integer:
ex. "1" == 1
you have to do this from 0 to 9.
unfortunately you cant manipulate a byte like c/c++ because this is just the openbor script and you must make do in this way.
BTW then you can use the logic operators to get a digit from a number and to recompose the whole num.
ex.
string is "7896".
use my getchar() func I posted somewhere to get the single digit.
then use shift (<<) and or (|) or + operator to recompose a number.
Its easy:
start from more significative digit. if your number is "7896" the digit is 7.
steps:
- 7
- 7 << 0x08 == 70 (byte not decimal) THIS IS AN EXAMPLE!! or 7*10 = 70 if you use decimal nums
- 70
- 70 | 8 = 78 or 70 + 8 if you work with decimal (not hexadecimal) numbers
- 78 << 0x08 == 780 or 78*10 if you use decimals
- 780 + 9 == 789
etc...
instead the shift operator you can use the exp func (my lib).
7*256 = 70 == 7*0xFF
7*(256^2) = 700 (byte) -----> 0x070000
this is the way.
so if you use hexadecimal nums you use SHIFT and OR operators.
with decimal nums you use * and + operators
most of the code to do this you can find in hi-score screen lib.
bye
ps. call this function stoi or atoi