string to integer?

Is val the best way to convert an string to an integer?

Depends where it came from. If the user typed it in, then it should be localized (thousands separator and decimal character), so you should use CDbl. If it is stored data, then you should have stored it non-localized (hint, hint) and you should use Val.

CDbl <–> Format
Val <–> Str

Seems I have a bottle neck in my code converting a time stamp in a file into a hour, minute, seconds, millesecond structure…
I do a lot of converting from character to integer. Are you saying I should have used CDbl?

ts=2017-08-16 13:31:11,298

[code]AsString = ts.mid(12, 12)

hour = val(AsString.Left(2))
minute = val(AsString.mid(4,2))
second = val(AsString.mid(7,2))
millesecond = val(AsString.mid(10,3))

inMilleseconds = hour * 3600000 + minute * 60000 + second * 1000 + millesecond[/code]

Where is the timestamp coming from? Might it sometimes use a dot for the decimal separator regardless if that’s “right” in the user’s current locale?

No, don’t use CDbl for that. You might get better performance using MidB instead of Mid, since the characters will always be ASCII. Mid has to read the string from the beginning. MidB can “index” it.

For short ASCII strings, Mid or MidB should not make a difference.

But you can run this in a loop and use activity monitor on Mac to see which part there takes most time.
And you may even replace val with some code to do it yourself.

For 2 to 3 digits, it could maybe be faster in Xojo.