String.Middle
From Xojo Documentation
Returns a portion of a string. The first character is numbered 0.
Syntax
result=stringVariable.Middle(start [,length])
Part | Type | Description |
---|---|---|
result | String | The portion of source from start and continuing for length characters or all remaining characters if length is not specified. |
source | String | Required. The string from which characters are returned. |
start | Integer | Required. The position of the first character to be returned.
The first character position is 0. If start is greater than the number of characters in source, an empty string is returned. |
length | Integer | Optional. The number of characters to return from source.
If omitted, all characters from start to the end of source are returned. If length + start is greater than the length of source, all characters from start to the end of source will be returned. |
stringVariable | String | Any variable of type String. |
Notes
To determine the number of characters in a string, use the String.Length function.
The Middle function works properly with international text.
Examples
These examples use the Middle function to return portions of a string.
Var source As String = "This is a test"
result = source.Middle(5) // returns "is a test"
result = source.Middle(10, 4) // returns "test"
This example converts the text string in TextField1 to hex and writes the result to TextField2:
For i As Integer = 1 To TextField1.Value.Length
TextField2.Value = TextField2.Value + "&h" + Hex(Asc(TextField1.Value.Middle(i, 1)))
Next
See Also
String for a complete list of functions.