how to convert text to value?

Blitz3D Forums/Blitz3D Beginners Area/how to convert text to value?

RXArt(Posted 2004) [#1]
I'm currently experimenting with string manipulation in blitz. I was wondering, let's say that I have a string with a number in front of it (eg: 3say, 4must). I can parse out the number using left$(), but how do I change the string to a value? Thanks!


GfK(Posted 2004) [#2]
A$ = "3say"
B% = Int(A$)



RXArt(Posted 2004) [#3]
heh! I thought int was only for numbers! but anyone, thanks so much, gfk!


GfK(Posted 2004) [#4]
You don't actually need the Int() - B% = A$ will work just the same. However, using Int() will keep your code more readable.


RXArt(Posted 2004) [#5]
:) Thanks for clarifying things for me. cheers


Mr.Waterlily(Posted 2004) [#6]
Perhaps you could clarify this issue:
If you run this code, the result is 35.
what should I to do get it to be 8?

a$="003"
b$="005"

a=Int(a$)
b=Int(b$)

c=a+b
Print c
WaitKey()
End



Gabriel(Posted 2004) [#7]
Use different variables to convert from string to int. A and B have already been defined as strings when you declared them with a$="003" and b$="005". Change the code to c=Int(a$) and d=Int(b$) and e=c+d and it works fine.


Mr.Waterlily(Posted 2004) [#8]
Aaah!

I knew it would be an easy fix! :)
The simplest things can be soooo hard to find!

Thanks!