Integer.FromText

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
Shared Method

Integer.FromText(theText As Text, Optional locale As Xojo.Core.Locale) As Integer

Supported for all project types and targets.

Converts a text form of a decimal number to an Integer. Specify a locale to convert thousands separator.

Notes

If no locale is specified, then Locale.Raw is used.

Exceptions

  • Xojo.Core.BadDataException when theText contains anything other than an integer (including when it is empty). Use Parse if you need to parse text that might contain non-numeric data or might be empty.

Sample Code

Convert a number in text to an integer:

Var value As Integer
value = Integer.FromText("42") // value = 42

This code converts a number using the US locale:

Var locale As New Xojo.Core.Locale("en-US")
Var value As Integer
value = Integer.FromText("1,234", locale) // value = 1234

You can also use an exception to catch invalid data:

// Exception raised for invalid text, so you can handle your own
// special cases.
Var value As Integer
Try
value = Integer.FromText("123ABC")
Catch e As BadDataException
value1 = -1 // if data is invalid, just use -1
End Try