Text.IndexOf

From Xojo Documentation

Method

Text.IndexOf(other As Text, Optional compareOptions As Integer = 0, Optional locale As Xojo.Core.Locale = Nil) As Integer

Supported for all project types and targets.

Finds the position of other within the text. Returns the zero-based location of other within the text. If other is not found, returns -1.

Parameters

Value Description
other The text to find within the original text.
compareOptions (Optional) Comparison options. Use constant CompareCaseSensitive for case-sensitive comparisons.
locale (Optional) The locale to use for comparisons. By default an invariant locale (not dependent on the system settings) is used.


Method

Text.IndexOf(startPosition As Integer, other As Text, Optional compareOptions As Integer = 0, Optional locale As Xojo.Core.Locale = Nil) As Integer

Supported for all project types and targets.

Finds the position of other within the text beginning with startPosition. Returns the zero-based location of other within the text. If other is not found, returns -1.

Parameters

Value Description
startPosition The zero-based starting position to begin the search.
other The text to find within the original text.
compareOptions (Optional) Comparison options. Use constant CompareCaseSensitive for case-sensitive comparisons.
locale (Optional) The locale to use for comparisons. By default an invariant locale (not dependent on the system settings) is used.

Notes

By default this performs a case-insensitive comparison. To do a case-sensitive comparison, supply the CompareCaseSensitive constant to the compareOptions parameter.

By default comparisons are done in an invariant locale (i.e. not dependent on the user's preferences). The locale parameter can be used to specify an explicit locale to do comparisons in.

Exceptions

Sample Code

Find the position of the text "wood":

Dim t As Text = "The woodchuck chucked wood."
Dim pos As Integer = t.IndexOf("wood") // pos = 4

Find the position of "wood" beginning with position 10:

Dim t As Text = "The woodchuck chucked wood."
Dim pos As Integer = t.IndexOf(10, "wood") // pos = 22