String to Int and vice versa

XverhelstX

Well-Known Member
Licensed User
Longtime User
Is there a way to change a string to an integer and an integer to a string.
e.g. VB:
B4X:
Cint ("10")

php:
B4X:
<?php
   $str = "10";
   $num = (int)$str;
?>

I need to use this for my library to send POST data.
B4X:
new BasicNameValuePair("srcY",src_y));

This is only String-String, as I need String - Integer. (For me, it's much easier to send POST data with Java)

So it there a way to change an integer into a string? (Int -> String)

XverhelstX
 
Last edited:

pappicio

Active Member
Licensed User
Longtime User
try in this way:

B4X:
''''''''''''''''''''''''''''''''
dim a as int
dim b as string
b="10"
a=b
''''''''''''''''''''''''''''''''''
'in this case a=10 (in integer format!)
'or
''''''''''''''''''''''''''''''''
dim a as int
dim b as string
a=10
b=a
'in this other case b="10" (in string format!)
''''''''''''''''''''''''''''''''''

so if an integer value is putted into a string var, it became a string, in implicit conversion.
and someone correct me if I'm wrong!
bye!
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
When converting a number to a string you are advised to use NumberFormat (or NumberFormat2), as you can get some odd results otherwise. Erel has explained it but I cannot find the reference.

Also IsNumber is useful to check that a string is valid as a number before trying to convert it.
 
Upvote 0
Top