M Maartensaps Member Licensed User Longtime User Nov 17, 2012 #1 I used to program in Clipper and Qbasic and in those there was a simple way to return the value of a string (if the string contains digits) It was VAL(string) and it would return the value of "string" starting at the first character, until the last or until the first non-digit-character. Basically it is the opposite of CHR(int) I would like to use it to convert stored strings (in a preference file) back to its numbers. Now I use a sub that compares and returns, but with multi-digit strings this becomes quit complex. Especially if a decimal sign is used.:BangHead: Did I miss it? or is it not there? And... will it be there in the future ? Maarten
I used to program in Clipper and Qbasic and in those there was a simple way to return the value of a string (if the string contains digits) It was VAL(string) and it would return the value of "string" starting at the first character, until the last or until the first non-digit-character. Basically it is the opposite of CHR(int) I would like to use it to convert stored strings (in a preference file) back to its numbers. Now I use a sub that compares and returns, but with multi-digit strings this becomes quit complex. Especially if a decimal sign is used.:BangHead: Did I miss it? or is it not there? And... will it be there in the future ? Maarten
Erel B4X founder Staff member Licensed User Longtime User Nov 17, 2012 #2 Basic4android compiler will convert strings automatically. For example this code is valid: Code: Copy Dim i As Int = "34" * 2
Basic4android compiler will convert strings automatically. For example this code is valid: Code: Copy Dim i As Int = "34" * 2
M Maartensaps Member Licensed User Longtime User Nov 17, 2012 #3 Great !!! Isn't life amazing. And I was building complicated subroutines with iterations that tested for numbers and decimal points etc etc etc... duh! Thanks!
Great !!! Isn't life amazing. And I was building complicated subroutines with iterations that tested for numbers and decimal points etc etc etc... duh! Thanks!
Erel B4X founder Staff member Licensed User Longtime User Nov 18, 2012 #4 Note that you can use IsNumber to test whether a string can be parsed to a numeric value. Basic4android Search: IsNumber
Note that you can use IsNumber to test whether a string can be parsed to a numeric value. Basic4android Search: IsNumber
Taha Member Licensed User Longtime User Mar 25, 2013 #5 Erel said: Basic4android compiler will convert strings automatically. For example this code is valid: Code: Copy Dim i As Int = "34" * 2 Click to expand... Can you make the same with: Code: Copy Dim i As Int = "34 * 2" :sign0089:
Erel said: Basic4android compiler will convert strings automatically. For example this code is valid: Code: Copy Dim i As Int = "34" * 2 Click to expand... Can you make the same with: Code: Copy Dim i As Int = "34 * 2" :sign0089:
M Mahares Expert Licensed User Longtime User Mar 26, 2013 #6 Code: Copy Dim i As Int = "34 * 2" 'Not valid Code: Copy Dim i As String = "34 * 2" 'returns: 34*2 Code: Copy Dim i As String = "34 * 2" Dim Member() As String Member=Regex.Split("\*",i) Msgbox(Member(0) *Member(1),"") 'returns 68 Code: Copy Dim i As Int = "34" * 2 'returns 68 Code: Copy Dim i As Int = "34" * "2" 'returns 68
Code: Copy Dim i As Int = "34 * 2" 'Not valid Code: Copy Dim i As String = "34 * 2" 'returns: 34*2 Code: Copy Dim i As String = "34 * 2" Dim Member() As String Member=Regex.Split("\*",i) Msgbox(Member(0) *Member(1),"") 'returns 68 Code: Copy Dim i As Int = "34" * 2 'returns 68 Code: Copy Dim i As Int = "34" * "2" 'returns 68
Erel B4X founder Staff member Licensed User Longtime User Mar 26, 2013 #7 See this library if you want to run "expressions": ExpressionEvaluator library