<div class="meta" robots="noindex">

</div>

DataType

# Text

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2021r1. Please use `String</api/data_types/string>` as a replacement.

</div>

## Description

The <span class="title-ref">Text</span> type is used to store textual information (unicode). <span class="title-ref">Text</span> values automatically convert to `String</api/data_types/string>`.

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                              | Parameters                                                                                                                                                                                                                       | Returns                                             | Shared |
|---------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|--------|
| `BeginsWith<text.beginswith>`                     | other As Text, options As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                                               | `Boolean</api/data_types/boolean>`                  |        |
| `Characters<text.characters>`                     |                                                                                                                                                                                                                                  | Xojo.Core.Iterable                                  |        |
| `Codepoints<text.codepoints>`                     |                                                                                                                                                                                                                                  | Xojo.Core.Iterable                                  |        |
| `Compare<text.compare>`                           | other As Text, `Optional</api/language/optional>` options As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                            | `Integer</api/data_types/integer>`                  |        |
| `Empty<text.empty>`                               |                                                                                                                                                                                                                                  | `Boolean</api/data_types/boolean>`                  |        |
| `EndOfLine<text.endofline>`                       |                                                                                                                                                                                                                                  | Text                                                |        |
| `EndsWith<text.endswith>`                         | other As Text, `Optional</api/language/optional>` options As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                            | `Boolean</api/data_types/boolean>`                  |        |
| `FromCString<text.fromcstring>`                   | str As `CString</api/data_types/additional_types/cstring>`, encoding As `TextEncoding</api/text/encoding_text/textencoding>`                                                                                                     | Text                                                | ✓      |
| `FromUnicodeCodepoint<text.fromunicodecodepoint>` | codepoint As `UInt32</api/data_types/additional_types/uint32>`                                                                                                                                                                   | Text                                                | ✓      |
| `IndexOf<text.indexof>`                           | other As Text, `Optional</api/language/optional>` compareOptions As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                     | `Integer</api/data_types/integer>`                  |        |
| `Join<text.join>`                                 | items() As Text, separator As Text                                                                                                                                                                                               | Text                                                | ✓      |
| `Left<text.left>`                                 | count As `Integer</api/data_types/integer>`                                                                                                                                                                                      | Text                                                |        |
| `Length<text.length>`                             |                                                                                                                                                                                                                                  | `Integer</api/data_types/integer>`                  |        |
| `Lowercase<text.lowercase>`                       | `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                                                                                                                 | Text                                                |        |
| `Mid<text.mid>`                                   | start As `Integer</api/data_types/integer>`                                                                                                                                                                                      | Text                                                |        |
|                                                   | start As `Integer</api/data_types/integer>`, length As `Integer</api/data_types/integer>`                                                                                                                                        | Text                                                |        |
| `Replace<text.replace>`                           | find As Text, replace As Text, `Optional</api/language/optional>` compareOptions As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`     | Text                                                |        |
| `ReplaceAll<text.replaceall>`                     | find As Text, replacement As Text, `Optional</api/language/optional>` compareOptions As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>` | Text                                                |        |
| `Right<text.right>`                               | count As `Integer</api/data_types/integer>`                                                                                                                                                                                      | Text                                                |        |
| `Split<text.split>`                               | separator As Text, `Optional</api/language/optional>` compareOptions As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                 | Text                                                |        |
| `TitleCase<text.titlecase>`                       | `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                                                                                                                 | Text                                                |        |
| `ToCString<text.tocstring>`                       | encoding As `TextEncoding</api/text/encoding_text/textencoding>`                                                                                                                                                                 | `CString</api/data_types/additional_types/cstring>` |        |
| `Trim<text.trim>`                                 |                                                                                                                                                                                                                                  | Text                                                |        |
| `TrimLeft<text.trimleft>`                         |                                                                                                                                                                                                                                  | Text                                                |        |
| `TrimRight<text.trimright>`                       |                                                                                                                                                                                                                                  | Text                                                |        |
| `Uppercase<text.uppercase>`                       | `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                                                                                                                 | Text                                                |        |

## Method descriptions

<div id="text.beginswith">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.BeginsWith

**BeginsWith**(other As Text, options As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As `Boolean</api/data_types/boolean>`

Determines whether the beginning of this <span class="title-ref">Text</span> instance matches the other <span class="title-ref">Text</span> when compared using the specified comparison options and locale. Returns True if other matches the beginning of the <span class="title-ref">Text</span>, False if it does not.

By default this performs a case-insensitive comparison. To do a case-sensitive comparison, supply the CompareCaseSensitive constant to the options 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.

<div class="warning">

<div class="title">

Warning

</div>

A `RuntimeException</api/exceptions/runtimeexception>` will be raised when options are invalid (currently not 0 or 1).

</div>

<div class="warning">

<div class="title">

Warning

</div>

An `InvalidArgumentException</api/exceptions/invalidargumentexception>` will be raised when other is an empty <span class="title-ref">Text</span> value.

</div>

Check the beginning characters of some \`Text\`:

``` xojo
Dim t As Text
t = "All we have to decide is what to do with the time that is given to us."

If t.BeginsWith("All") Then
  Label1.Text = "Text starts with 'All'."
End If
```

<div id="text.characters">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Characters

**Characters** As Xojo.Core.Iterable

Returns an iterator that yields a <span class="title-ref">Text</span> value for each character, in order of first to last.

Reverse the \`Text\`:

``` xojo
Dim t As Text = "Hello, World!"
Dim reverse As Text

For Each c As Text In t.Characters
  reverse = c + reverse
Next

' reverse = "!dlroW ,olleH"
```

<div id="text.codepoints">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Codepoints

**Codepoints** As Xojo.Core.Iterable

Returns an iterator that returns UInt32 values for each Unicode scalar value that comprises the <span class="title-ref">Text</span>.

Look for Unicode 65:

``` xojo
Dim myText As Text = "Once Upon A Time"
For Each codePoint As UInt32 In myText.Codepoints
  If codePoint = 65 Then
    ' It is "A"
  End If
Next
```

<div id="text.compare">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Compare

**Compare**(other As Text, `Optional</api/language/optional>` options As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As `Integer</api/data_types/integer>`

Compares a <span class="title-ref">Text</span> value with another <span class="title-ref">Text</span> value. A non-empty <span class="title-ref">Text</span> is always greater than an empty <span class="title-ref">Text</span>. By default, a case-insensitive comparison is done. Returns a negative integer if the value is less than other, 0 if the two values are equal, and a positive integer if the value is greater than other.

By default this performs a case-insensitive comparison. To do a case-sensitive comparison, supply the CompareCaseSensitive constant to the options 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.

<div class="warning">

<div class="title">

Warning

</div>

A `RuntimeException</api/exceptions/runtimeexception>` will be raised when the specified options are invalid.

</div>

Compare two <span class="title-ref">Text</span> values:

``` xojo
Dim dog As Text = "Dog"
Dim cat As Text = "Cat"

Dim result As Integer
result = dog.Compare(cat)

' result > 0
```

<div id="text.empty">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Empty

**Empty** As `Boolean</api/data_types/boolean>`

Returns whether or not the <span class="title-ref">Text</span> has contents. This will always be as fast or faster than checking length against zero. Returns True when the <span class="title-ref">Text</span> is empty, False when it is not.

Check if a <span class="title-ref">Text</span> value is empty:

``` xojo
Dim t As Text = ""

If t.Empty Then
  t = "Hello"
End If
```

<div id="text.endofline">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.EndOfLine

**EndOfLine** As Text

Returns the EndOfLine character for the current platform (Mac, Windows, Linux and iOS).

- iOS uses CodePoint 13
- Mac and Linux use CodePoint 10
- Windows uses CodePoint 10 + CodePoint 13

<div id="text.endswith">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.EndsWith

**EndsWith**(other As Text, `Optional</api/language/optional>` options As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As `Boolean</api/data_types/boolean>`

Determines if the <span class="title-ref">Text</span> ends with other <span class="title-ref">Text</span>. Returns True if the <span class="title-ref">Text</span> ends with other, False if it does not.

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.

<div class="warning">

<div class="title">

Warning

</div>

A `RuntimeException</api/exceptions/runtimeexception>` will be raised if the options specified are invalid.

</div>

<div class="warning">

<div class="title">

Warning

</div>

An `InvalidArgumentException</api/exceptions/invalidargumentexception>` will be raised if other is an empty <span class="title-ref">Text</span> value.

</div>

<div id="text.fromcstring">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.FromCString

**FromCString**(str As `CString</api/data_types/additional_types/cstring>`, encoding As `TextEncoding</api/text/encoding_text/textencoding>`) As Text

Creates a new <span class="title-ref">Text</span> object from a CString, interpreting it using the given encoding.

This method is `shared</api/language/shared>`.

<div id="text.fromunicodecodepoint">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.FromUnicodeCodepoint

**FromUnicodeCodepoint**(codepoint As `UInt32</api/data_types/additional_types/uint32>`) As Text

Creates a new <span class="title-ref">Text</span> object from a single Unicode code point value.

This method is `shared</api/language/shared>`.

Visit [Unicode Lookup](http://unicodelookup.com/) to get decimal values to use with this method.

<div class="warning">

<div class="title">

Warning

</div>

An `UnsupportedFormatException</api/exceptions/unsupportedformatexception>` will be raised if codepoint is not a Unicode scalar value (i.e. it is a high-surrogate code point or a low-surrogate code point).

</div>

Get the EndOfLine character:

``` xojo
Dim EOL As Text = Text.FromUnicodeCodepoint(10)
```

Get the trade mark character (™):

``` xojo
Dim tradeMark As Text = Text.FromUnicodeCodepoint(8482)
```

Get the pi character (π) using its hex value:

``` xojo
Dim piChar As Text = Text.FromUnicodeCodepoint(&h3C0)
```

<div id="text.indexof">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.IndexOf

**IndexOf**(other As Text, `Optional</api/language/optional>` compareOptions As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As `Integer</api/data_types/integer>`

Finds the position of other within the <span class="title-ref">Text</span> beginning with *startPosition*. Returns the zero-based location of *other* within the <span class="title-ref">Text</span>. If *other* is not found, returns -1.

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.

<div class="warning">

<div class="title">

Warning

</div>

A `RuntimeException</api/exceptions/runtimeexception>` will be raised if the specified options are invalid.

</div>

<div class="warning">

<div class="title">

Warning

</div>

An `InvalidArgumentException</api/exceptions/invalidargumentexception>` will be raised if *other* is an empty <span class="title-ref">Text</span> value.

</div>

Find the position of the <span class="title-ref">Text</span> "wood":

``` xojo
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:

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

<div id="text.join">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Join

**Join**(items() As Text, separator As Text) As Text

Creates a new <span class="title-ref">Text</span> object by concatenating each item in the items array together. If separator is not empty, it will be inserted between each item when performing the concatenation. If the items array is empty, an empty <span class="title-ref">Text</span> value is returned.

This method is `shared</api/language/shared>`.

Create a <span class="title-ref">Text</span> from the array containing "Hello" and "World":

``` xojo
Dim words() As Text = Array("Hello", "World")

Dim newText As Text
newText = Text.Join(words, ",") ' newText = "Hello,World"
```

<div id="text.left">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Left

**Left**(count As `Integer</api/data_types/integer>`) As Text

Returns the first count characters of the <span class="title-ref">Text</span> value.

Get the 5 left-most characters of the \`Text\`:

``` xojo
Dim t As Text = "Hello, World!"
Dim hello As Text = t.Left(5) ' hello = "Hello"
```

<div id="text.length">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Length

**Length** As `Integer</api/data_types/integer>`

Returns the number of characters in the <span class="title-ref">Text</span>.

Get the length of some \`Text\`:

``` xojo
Dim t As Text = "Hello, World!"
Dim length As Integer = t.Length ' length = 13
```

<div id="text.lowercase">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Lowercase

**Lowercase**(`Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As Text

Creates a new <span class="title-ref">Text</span> value that has its characters lowercased. If locale is non-Nil, it uses the locale's rules when performing the operation.

Set <span class="title-ref">Text</span> to lower case:

``` xojo
Dim t As Text = "Hello, World!"
t = t.Lowercase ' t = "hello, world!"
```

<div id="text.mid">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Mid

**Mid**(start As `Integer</api/data_types/integer>`) As Text

Returns a portion of the characters in the <span class="title-ref">Text</span> value. The start position is a zero-based. If the <span class="title-ref">Text</span> value is shorter than the requested length of characters, the remaining <span class="title-ref">Text</span> starting at the start is returned.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="rst-class">

forsearch

</div>

Text.Mid

**Mid**(start As `Integer</api/data_types/integer>`, length As `Integer</api/data_types/integer>`) As Text

Returns a portion of the characters in the <span class="title-ref">Text</span> value. The start position is a zero-based. If the <span class="title-ref">Text</span> value is shorter than the requested length of characters, the remaining <span class="title-ref">Text</span> starting at the start is returned.

Get "World!" from \`Text\`:

``` xojo
Dim t As Text = "Hello, World!"
t = t.Mid(7) ' t = "World!"
```

Get "World" from \`Text\`:

``` xojo
Dim t As Text = "Hello, World!"
t = t.Mid(7, 5) ' t = "World"
```

<div id="text.replace">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Replace

**Replace**(find As Text, replace As Text, `Optional</api/language/optional>` compareOptions As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As Text

Creates a new value by replacing the first instances of the find parameter's value with the replacement parameter's value. If the input does not contain the requested value, nothing is replaced and the input is returned.

By default this performs a case-insensitive comparison search. 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.

<div class="warning">

<div class="title">

Warning

</div>

A `RuntimeException</api/exceptions/runtimeexception>` will be raised if the options specified are invalid.

</div>

<div class="warning">

<div class="title">

Warning

</div>

An `InvalidArgumentException</api/exceptions/invalidargumentexception>` will be raised if find is an empty <span class="title-ref">Text</span> value.

</div>

Replace "World" with "Mars":

``` xojo
Dim t As Text = "Hello, World!"

Dim newText As Text
newText = t.Replace("World", "Mars") ' newText = "Hello, Mars!"
```

<div id="text.replaceall">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.ReplaceAll

**ReplaceAll**(find As Text, replacement As Text, `Optional</api/language/optional>` compareOptions As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As Text

Returns a new <span class="title-ref">Text</span> value by replacing all instances of the find parameter's value with the replacement parameter's value. If the input does not contain the requested value, nothing is replaced and the input is returned.

By default this performs a case-insensitive comparison search. 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.

<div class="warning">

<div class="title">

Warning

</div>

A `RuntimeException</api/exceptions/runtimeexception>` will be raised if the options specified are invalid.

</div>

<div class="warning">

<div class="title">

Warning

</div>

An `InvalidArgumentException</api/exceptions/invalidargumentexception>` will be raised if find is an empty <span class="title-ref">Text</span> value.

</div>

Replaces all instances of "l" with "1":

``` xojo
Dim t As Text = "Hello, World!"

Dim newText As Text
newText = t.ReplaceAll("l", "L") ' newText = "HeLLo, WorLd!"
```

<div id="text.right">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Right

**Right**(count As `Integer</api/data_types/integer>`) As Text

Returns the last count characters of the <span class="title-ref">Text</span> value.

Get "World!" from \`Text\`:

``` xojo
Dim t As Text = "Hello, World!"
t = t.Right(6) ' t = "World!"
```

<div id="text.split">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Split

**Split**(separator As Text, `Optional</api/language/optional>` compareOptions As `Integer</api/data_types/integer>` = 0, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As Text

Returns an array of the portions of the <span class="title-ref">Text</span> that are delimited by separator. If separator is the same as the <span class="title-ref">Text</span>, an empty array is returned. If the <span class="title-ref">Text</span> does not contain separator, an array containing only the original <span class="title-ref">Text</span> value is returned.

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.

Split provides equivalent functionality to String.NthField.

<div class="warning">

<div class="title">

Warning

</div>

A `RuntimeException</api/exceptions/runtimeexception>` will be raised if the options specified are invalid.

</div>

<div class="warning">

<div class="title">

Warning

</div>

An `InvalidArgumentException</api/exceptions/invalidargumentexception>` will be raised if find is an empty <span class="title-ref">Text</span> value.

</div>

Split the <span class="title-ref">Text</span> into "Hello" and "World":

``` xojo
Dim t As Text = "Hello World"

Dim words() As Text
words = t.Split(" ")
```

Splits the <span class="title-ref">Text</span> into an array with one element for each character:

``` xojo
Dim t As Text = "Hello, World!"

Dim chars() As Text
chars = t.Split
```

<div id="text.titlecase">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.TitleCase

**TitleCase**(`Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As Text

Returns a new <span class="title-ref">Text</span> value that has its characters titlecased. If the locale parameter is non-Nil, it will use that locale's rules when performing the operation.

Convert <span class="title-ref">Text</span> to "Hello, World!":

``` xojo
Dim t As Text = "hello, world!"
t = t.TitleCase ' t = "Hello, World!"
```

<div id="text.tocstring">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.ToCString

**ToCString**(encoding As `TextEncoding</api/text/encoding_text/textencoding>`) As `CString</api/data_types/additional_types/cstring>`

Creates a CString from a <span class="title-ref">Text</span> with a specific encoding. The CString is immutable and is its own entity with the lifetime not tied to the source <span class="title-ref">Text</span> value. This is provided to make dealing with declares easier.

In general, CString is for use with Declare commands and MemoryBlocks.

<div class="warning">

<div class="title">

Warning

</div>

A `NilObjectException</api/exceptions/nilobjectexception>` will be raised if encoding is Nil.

</div>

<div class="warning">

<div class="title">

Warning

</div>

An `UnsupportedFormatException</api/exceptions/unsupportedformatexception>` will be raised if the <span class="title-ref">Text</span> is cannot be represented in the given encoding. For example, Emoji is not representable in the ASCII encoding.

</div>

Convert <span class="title-ref">Text</span> to CString:

``` xojo
Dim t As Text = "Hello, World!"
Dim cs As CString = t.ToCString(Xojo.Core.TextEncoding.UTF8)
```

<div id="text.trim">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Trim

**Trim** As Text

Trims whitespace, as defined in the Unicode standard, from the beginning and end of the <span class="title-ref">Text</span>. If the value is empty or consists entirely of whitespace, an empty <span class="title-ref">Text</span> is returned.

Removes beginning and ending white space:

``` xojo
Dim t As Text = "   Hello, World!    "
t = t.Trim ' t = "Hello, World!"
```

<div id="text.trimleft">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.TrimLeft

**TrimLeft** As Text

Trims whitespace, as defined in the Unicode standard, from the beginning of the <span class="title-ref">Text</span>. If the value is empty or consists entirely of whitespace, an empty <span class="title-ref">Text</span> is returned.

Removes beginning white space:

``` xojo
Dim t As Text = "   Hello, World!    "
t = t.TrimLeft ' t = "Hello, World!    "
```

<div id="text.trimright">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.TrimRight

**TrimRight** As Text

Trims whitespace, as defined in the Unicode standard, from end of the <span class="title-ref">Text</span>. If the value is empty or consists entirely of whitespace, an empty <span class="title-ref">Text</span> is returned.

Removes ending white space:

``` xojo
Dim t As Text = "   Hello, World!    "
t = t.TrimRight ' t = "   Hello, World!"
```

<div id="text.uppercase">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Text.Uppercase

**Uppercase**(`Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As Text

Returns a new <span class="title-ref">Text</span> value that has its characters uppercased. If the locale parameter is non-Nil, it will use that locale's rules when performing the operation.

Set <span class="title-ref">Text</span> to upper case:

``` xojo
Dim t As Text = "Hello, World!"
t = t.Uppercase ' t = "HELLO, WORLD!"
```

## Notes

Const CompareCaseSensitive = 1

Used by methods to specify some methods should compare <span class="title-ref">Text</span> as case sensistive.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Converting text to and from bytes

To get the bytes for the <span class="title-ref">Text</span> (using a MemoryBlock), you call TextEncoding.ConvertTextToData using a specific encoding.

To convert bytes in a MemoryBlock to <span class="title-ref">Text</span>, you call TextEncoding.ConvertDataToText, specifying the encoding.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Comparing text vs. strings

Text is abstract - a series of characters.

Bytes are concrete - a series of bits.

There are lots of different ways to encode characters into bytes. Most of them are very limited, only defining encodings for some characters, and even when they define encodings for the same characters, they often use different bytes.

The only encodings which can represent every character are the Unicode encodings: UTF-8, UTF-16, UTF-32.

The old String type tries to represent either <span class="title-ref">Text</span> or bytes or both, and as a result it's complicated and confusing. With <span class="title-ref">Text</span>, this is now very simple: <span class="title-ref">Text</span> is characters, and if you want to convert to or from an array of bytes (or an old-fashioned String), you have to be clear about the encoding you intend to use.

When you say that you want to write an ASCII string to a serial port - well, you are actually writing bytes to the serial port, because you are doing something concrete, something that interchanges with other programs or machines. So you would convert the <span class="title-ref">Text</span> to bytes, and you would do so using the ASCII encoding. Conversely, you can translate some bytes, contained in a String or a MemoryBlock, up to a <span class="title-ref">Text</span> value by specifying the encoding that was used to generate them.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Technical information

The <span class="title-ref">Text</span> type is an immutable series of Unicode scalar values.

The documentation is very deliberate in its use of these terms: character, code point, and scalar value. A character, in this context, refers to an extended grapheme cluster (also known as a user-perceived character). The terms code point and scalar value retain the meaning defined in the Unicode standard.

All of the APIs on the <span class="title-ref">Text</span> type operate in characters. For example, if the APIs worked in terms of Unicode code points, it would be possible to corrupt data using Left/Mid/Right if the positions happened to be in the middle of a composed character or grapheme cluster. Working in characters also avoids situations where the length of 'é' can be either 1 or 2.

Many of the functions in this API optionally take locales because different locales can have special rules for casing and comparing. The default behavior being to perform the operation in a locale-insensitive manner. Functions that perform comparisons also take option flags that specify how to perform the comparison (e.g. case sensitively). These flags are bit flags that are combined via the bitwise Or operator. If the combination of options is invalid, an exception is thrown.

## Sample code

Assign <span class="title-ref">Text</span> to a Label:

``` xojo
Dim t As Text
t = "Hello, World"
MyLabel.Text = t
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Text is available in all project types, so you can also use it in place of String. A <span class="title-ref">Text</span> value can be converted to a String, so code like this works:

``` xojo
Dim t As Text = "Hello, World!"
MessageBox(t) ' MessageBox takes a String, but this works because Text can be converted to String
```

You can also convert a String with a known encoding to a <span class="title-ref">Text</span> using the String.ToText method:

``` xojo
Var s As String = "Hello"
Var t As Text = s.ToText ' t = "Hello"
```

## Compatibility

All project types on all supported operating systems.

## See also

`TextEncoding</api/text/encoding_text/textencoding>` class
