Hello all.
:sign0085:
I'm having trouble using the LastIndexOf and IndexOf functions in my app.
So to test what's happening, I wrote a simple testprogram that looks like :
Now what I expected was that IndexOf would give other results then LastIndexOf would give me depending of the position of the "." in the Amount-string, but my tests show the same results for both :
Amount = 12
LastIndexOf pos = -1
Amount = 12
IndexOf pos = -1
Amount = 123.4
LastIndexOf pos = 3
Amount = 123.4
IndexOf pos = 3
Amount = 1234.56
LastIndexOf pos = 4
Amount = 1234.56
IndexOf pos = 4
Amount = 12345.67
LastIndexOf pos = 5
Amount = 12345.67
IndexOf pos = 5
Amount = 123456.789
LastIndexOf pos = 6
Amount = 123456.789
IndexOf pos = 6
Can anyone tell me what I do wrong or whatever is happening?
What I really like to use, but can't find anywhere is a function like in VB or VBA to format numerical strings, like the old fashioned print using "###.##"
:sign0085:
I'm having trouble using the LastIndexOf and IndexOf functions in my app.
So to test what's happening, I wrote a simple testprogram that looks like :
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Amount As String
Dim pos As Int : pos = 0
End Sub
Sub Activity_Create(FirstTime As Boolean)
Amount = "12"
UseLastIndexOf
UseIndexOf
Amount = "123.4"
UseLastIndexOf
UseIndexOf
Amount = "1234.56"
UseLastIndexOf
UseIndexOf
Amount = "12345.67"
UseLastIndexOf
UseIndexOf
Amount = "123456.789"
UseLastIndexOf
UseIndexOf
End Sub
Sub UseLastIndexOf
Log("Amount = " & Amount)
pos = Amount.LastIndexOf(".")
Log("LastIndexOf pos = " & pos)
Log(" ")
End Sub
Sub UseIndexOf
Log("Amount = " & Amount)
pos = Amount.IndexOf(".")
Log("IndexOf pos = " & pos)
Log(" ")
End Sub
Sub Activity_Resume
End Sub
Now what I expected was that IndexOf would give other results then LastIndexOf would give me depending of the position of the "." in the Amount-string, but my tests show the same results for both :
Amount = 12
LastIndexOf pos = -1
Amount = 12
IndexOf pos = -1
Amount = 123.4
LastIndexOf pos = 3
Amount = 123.4
IndexOf pos = 3
Amount = 1234.56
LastIndexOf pos = 4
Amount = 1234.56
IndexOf pos = 4
Amount = 12345.67
LastIndexOf pos = 5
Amount = 12345.67
IndexOf pos = 5
Amount = 123456.789
LastIndexOf pos = 6
Amount = 123456.789
IndexOf pos = 6
Can anyone tell me what I do wrong or whatever is happening?
What I really like to use, but can't find anywhere is a function like in VB or VBA to format numerical strings, like the old fashioned print using "###.##"