DataType

# String

<div class="rst-class">

forsearch

</div>

DataType

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

## Description

A <span class="title-ref">String</span> is an intrinsic data type. It is a series of numeric or alphabetic characters enclosed in quotes.

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                            | Parameters                                                                                                                                                                                                                                                                                      | Returns                                              | Shared |
|-------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------|--------|
| `Asc<string.asc>`                               |                                                                                                                                                                                                                                                                                                 | `Integer</api/data_types/integer>`                   |        |
| `AscByte<string.ascbyte>`                       |                                                                                                                                                                                                                                                                                                 | `Integer</api/data_types/integer>`                   |        |
| `BeginsWith<string.beginswith>`                 | value As String, options As `ComparisonOptions</api/language/comparisonoptions>` = `ComparisonOptions.CaseInsensitive</api/language/comparisonoptions>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                                                          | `Boolean</api/data_types/boolean>`                   |        |
| `Bytes<string.bytes>`                           |                                                                                                                                                                                                                                                                                                 | `Integer</api/data_types/integer>`                   |        |
| `CDbl<string.cdbl>`                             | `Extends</api/language/extends>` str As `String</api/data_types/string>`                                                                                                                                                                                                                        | `Double</api/data_types/double>`                     |        |
| `CharacterCount<string.charactercount>`         |                                                                                                                                                                                                                                                                                                 | `Integer</api/data_types/integer>`                   |        |
| `Characters<string.characters>`                 |                                                                                                                                                                                                                                                                                                 | `String()</api/data_types/string>`                   |        |
| `Chr<string.chr>`                               | value As `Integer</api/data_types/integer>`                                                                                                                                                                                                                                                     | String                                               | ✓      |
| `ChrByte<string.chrbyte>`                       | value As `Integer</api/data_types/integer>`                                                                                                                                                                                                                                                     | String                                               | ✓      |
| `Codepoints<string.codepoints>`                 |                                                                                                                                                                                                                                                                                                 | `Integer()</api/data_types/integer>`                 |        |
| `Compare<string.compare>`                       | other As String, `Optional</api/language/optional>` comparison As `ComparisonOptions</api/language/comparisonoptions>` = `ComparisonOptions.CaseInsensitive</api/language/comparisonoptions>`, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>` | `Integer</api/data_types/integer>`                   |        |
| `Contains<string.contains>`                     | searchString As `String</api/data_types/string>`, options As `ComparisonOptions</api/language/comparisonoptions>` = `ComparisonOptions.CaseInsensitive</api/language/comparisonoptions>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                         | `Boolean</api/data_types/boolean>`                   |        |
| `ConvertEncoding<string.convertencoding>`       | newEncoding As `TextEncoding</api/text/encoding_text/textencoding>`                                                                                                                                                                                                                             | String                                               |        |
| `CountFields<string.countfields>`               | separator As String                                                                                                                                                                                                                                                                             | `Integer</api/data_types/integer>`                   |        |
| `DefineEncoding<string.defineencoding>`         | enc As `TextEncoding</api/text/encoding_text/textencoding>`                                                                                                                                                                                                                                     | String                                               |        |
| `EndOfLine<string.endofline>`                   |                                                                                                                                                                                                                                                                                                 | `EndOfLine</api/text/endofline>`                     | ✓      |
| `Encoding<string.encoding>`                     |                                                                                                                                                                                                                                                                                                 | `TextEncoding</api/text/encoding_text/textencoding>` |        |
| `EndsWith<string.endswith>`                     | value As String, options As `ComparisonOptions</api/language/comparisonoptions>` = `ComparisonOptions.CaseInsensitive</api/language/comparisonoptions>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                                                          | `Boolean</api/data_types/boolean>`                   |        |
| `FromArray<string.fromarray>`                   | fields() As String, delimiter As String = " "                                                                                                                                                                                                                                                   | String                                               | ✓      |
| `IndexOf<string.indexof>`                       | searchString As String, options As `ComparisonOptions</api/language/comparisonoptions>` = `ComparisonOptions.CaseInsensitive</api/language/comparisonoptions>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                                                   | `Integer</api/data_types/integer>`                   |        |
|                                                 | startPosition As `Integer</api/data_types/integer>`, searchString As String, options As `ComparisonOptions</api/language/comparisonoptions>` = `ComparisonOptions.CaseInsensitive</api/language/comparisonoptions>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`              | `Integer</api/data_types/integer>`                   |        |
| `IndexOfBytes<string.indexofbytes>`             | start As `Integer</api/data_types/integer>` = 0, find As String                                                                                                                                                                                                                                 | `Integer</api/data_types/integer>`                   |        |
| `IsEmpty<string.isempty>`                       |                                                                                                                                                                                                                                                                                                 | `Boolean</api/data_types/boolean>`                   |        |
| `IsNumeric<string.isnumeric>`                   |                                                                                                                                                                                                                                                                                                 | `Boolean</api/data_types/boolean>`                   |        |
| `LastField<string.lastfield>`                   | separator As String                                                                                                                                                                                                                                                                             | `String</api/data_types/string>`                     |        |
| `Left<string.left>`                             | count As `Integer</api/data_types/integer>`                                                                                                                                                                                                                                                     | String                                               |        |
| `LeftBytes<string.leftbytes>`                   | count As `Integer</api/data_types/integer>`                                                                                                                                                                                                                                                     | String                                               |        |
| `Length<string.length>`                         |                                                                                                                                                                                                                                                                                                 | `Integer</api/data_types/integer>`                   |        |
| `Lowercase<string.lowercase>`                   | locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                                                                                                                                                                                                                   | String                                               |        |
| `Middle<string.middle>`                         | index As `Integer</api/data_types/integer>`, `Optional</api/language/optional>` length As `Integer</api/data_types/integer>`                                                                                                                                                                    | String                                               |        |
| `MiddleBytes<string.middlebytes>`               | start As `Integer</api/data_types/integer>`, `Optional</api/language/optional>` length As `Integer</api/data_types/integer>`                                                                                                                                                                    | String                                               |        |
| `NthField<string.nthfield>`                     | separator As String, fieldNumber As `Integer</api/data_types/integer>`                                                                                                                                                                                                                          | String                                               |        |
| `Replace<string.replace>`                       | substring As String, replacementString As String                                                                                                                                                                                                                                                | String                                               |        |
| `ReplaceAll<string.replaceall>`                 | substring As String, replacementString As String                                                                                                                                                                                                                                                | String                                               |        |
| `ReplaceAllBytes<string.replaceallbytes>`       | substring As String, replacementString As String                                                                                                                                                                                                                                                | String                                               |        |
| `ReplaceBytes<string.replacebytes>`             | substring As String, replacementString As String                                                                                                                                                                                                                                                | String                                               |        |
| `ReplaceLineEndings<string.replacelineendings>` | replacement As String                                                                                                                                                                                                                                                                           | String                                               |        |
| `Right<string.right>`                           | count As `Integer</api/data_types/integer>`                                                                                                                                                                                                                                                     | String                                               |        |
| `RightBytes<string.rightbytes>`                 | count As `Integer</api/data_types/integer>`                                                                                                                                                                                                                                                     | String                                               |        |
| `Split<string.split>`                           | delimiter As String = " "                                                                                                                                                                                                                                                                       | String()                                             |        |
| `SplitBytes<string.splitbytes>`                 | delimiter As String = " "                                                                                                                                                                                                                                                                       | String()                                             |        |
| `Titlecase<string.titlecase>`                   | locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                                                                                                                                                                                                                   | String                                               |        |
| `ToArray<string.toarray>`                       | delimiter As String = " "                                                                                                                                                                                                                                                                       | String()                                             |        |
| `ToBoolean<string.toboolean>`                   |                                                                                                                                                                                                                                                                                                 | `Boolean</api/data_types/boolean>`                   |        |
| `ToDouble<string.todouble>`                     |                                                                                                                                                                                                                                                                                                 | `Double</api/data_types/double>`                     |        |
| `ToInt64<string.toint64>`                       |                                                                                                                                                                                                                                                                                                 | `Int64</api/data_types/additional_types/int64>`      |        |
| `ToInteger<string.tointeger>`                   |                                                                                                                                                                                                                                                                                                 | `Integer</api/data_types/integer>`                   |        |
| `Trim<string.trim>`                             | `Optional</api/language/optional>` `ParamArray</api/language/paramarray>` characters() As String                                                                                                                                                                                                | String                                               |        |
| `TrimLeft<string.trimleft>`                     | `Optional</api/language/optional>` `ParamArray</api/language/paramarray>` characters() As String                                                                                                                                                                                                | String                                               |        |
| `TrimRight<string.trimright>`                   | `Optional</api/language/optional>` `ParamArray</api/language/paramarray>` characters() As String                                                                                                                                                                                                | String                                               |        |
| `Uppercase<string.uppercase>`                   | locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                                                                                                                                                                                                                   | String                                               |        |
| `Val<string.val>`                               |                                                                                                                                                                                                                                                                                                 | `Double</api/data_types/double>`                     |        |

## Method descriptions

<div id="string.asc">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Asc

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

> Returns the integer code point for the first character in the <span class="title-ref">String</span> using the character's encoding.
>
> The Asc function returns the [code point](http://en.wikipedia.org/wiki/Code_point) for the first character in the passed <span class="title-ref">String</span> in the characters encoding. Characters 0 through 127 are the standard ASCII set, which are the same on practically every encoding.
>
> If you need to get the ASCII code of the first byte of the <span class="title-ref">String</span> rather than the first character, use the `AscByte<string.ascbyte>` function.
>
> This example uses the Asc function to get the ASCII value of a character.
>
> ``` xojo
> Var result As Integer
> Var source As String = "A"
> result = source.Asc ' returns 65
> ```
>
> This example gets the code point for the "&#8805;" symbol
>
> ``` xojo
> Var source As String = "≥"
> Var result As Integer
> result = source.Asc
> ```

<div id="string.ascbyte">

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

</div>

<div class="rst-class">

forsearch

</div>

String.AscByte

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

> Returns the integer value for the first byte of a <span class="title-ref">String</span>.
>
> This function returns the code for the first byte in the <span class="title-ref">String</span> passed. If you need to get the character code of the first character of the <span class="title-ref">String</span> rather than the first byte, use the `String</api/data_types/string>` function instead.
>
> You should use AscByte instead of Asc when the <span class="title-ref">String</span> represents binary data.
>
> This code gets the value of the first byte of a \`String\`:
>
> ``` xojo
> Var s1 As String = "a"
> Var byte As Integer
> byte = s1.AscByte ' returns 97
>
> Var s2 As String = "A"
> byte = s2.AscByte ' returns 65
> ```

<div id="string.beginswith">

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

</div>

<div class="rst-class">

forsearch

</div>

String.BeginsWith

**BeginsWith**(value As String, options As `ComparisonOptions</api/language/comparisonoptions>` = `ComparisonOptions.CaseInsensitive</api/language/comparisonoptions>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As `Boolean</api/data_types/boolean>`

> Returns `True</api/language/true>` if the <span class="title-ref">String</span> begins with the *value* passed.
>
> BeginsWith tells you whether or not the source <span class="title-ref">String</span> begins with the *value* passed based upon the comparison *options* (case-sensitive or case-insensitive) and *locale* specified.
>
> This example uses the BeginsWith function determine if the source <span class="title-ref">String</span> begins with "Inc.":
>
> ``` xojo
> Var s As String
> s = "Xojo, Inc."
> If s.BeginsWith("Xojo", ComparisonOptions.CaseSensitive, Locale.Current) Then
> System.Beep
> MessageBox("It begins with Xojo.")
> End If
> ```

<div id="string.bytes">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Bytes

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

> Returns the number of bytes in the specified <span class="title-ref">String</span>.
>
> Bytes treats <span class="title-ref">String</span> as a series of bytes, rather than a series of characters. It should be used when <span class="title-ref">String</span> represents binary data. If you need to know the number of characters in <span class="title-ref">String</span> rather than the number of bytes, use the `Length<string.length>` function.
>
> This example uses the Bytes function to return the number of bytes in a <span class="title-ref">String</span>.
>
> ``` xojo
> Var s As String
> s = "Hello World"
> n = s.Bytes ' returns 11
> ```

<div id="string.cdbl">

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

</div>

<div class="rst-class">

forsearch

</div>

String.CDbl

**CDbl**(`Extends</api/language/extends>` str As `String</api/data_types/string>`) As `Double</api/data_types/double>`

> Returns the *str* passed as a `Double</api/data_types/double>`.

<div id="string.charactercount">

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

</div>

<div class="rst-class">

forsearch

</div>

String.CharacterCount

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

> Returns the number of visually distinct characters in the <span class="title-ref">String</span>.
>
> In most cases, this will be the same value that would be returned by `Length<string.length>`. It will differ when the <span class="title-ref">String</span> contains characters (such as emojis and characters from some written language character sets) each of which is a visually distinct single character but may require more than one [unit of storage](https://en.wikipedia.org/wiki/Code_point) per character.

<div id="string.characters">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Characters

**Characters** As `String()</api/data_types/string>`

> Returns the <span class="title-ref">string</span> in an `array</api/language/array>` where each visually distinct character is a single element.
>
> This example is a function that takes a <span class="title-ref">String</span> (source) then returns the number of asterisks in it:
>
> ``` xojo
> Var count As Integer
> For Each char As String In source.Characters
> if char = "*" then count = count + 1
> Next
>
> Return count
> ```

<div id="string.chr">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Chr

**Chr**(value As `Integer</api/data_types/integer>`) As <span class="title-ref">String</span>

> Returns the *value* passed as a `String</api/data_types/string>`.
>
> This method is `shared</api/language/shared>`.

<div id="string.chrbyte">

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

</div>

<div class="rst-class">

forsearch

</div>

String.ChrByte

**ChrByte**(value As `Integer</api/data_types/integer>`) As <span class="title-ref">String</span>

> Returns a single byte <span class="title-ref">String</span> from the specified *value*.
>
> This method is `shared</api/language/shared>`.
>
> <div class="tip">
>
> <div class="title">
>
> Tip
>
> </div>
>
> Use ChrByte instead of `Chr</api/text/chr>` when working with binary data.
>
> </div>

<div id="string.codepoints">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Codepoints

**Codepoints** As `Integer()</api/data_types/integer>`

> Returns an `array</api/language/array>` of `Integer()</api/data_types/integer>` values for each Unicode scalar value that comprises the <span class="title-ref">String</span>.
>
> Look for Unicode 65:
>
> ``` xojo
> Var myString As String = "Once Upon A Time"
> For Each codePoint As Integer In myString.Codepoints
> If codePoint = 65 Then
>     ' It is "A"
> End If
> Next
> ```

<div id="string.compare">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Compare

**Compare**(other As String, `Optional</api/language/optional>` comparison As `ComparisonOptions</api/language/comparisonoptions>` = `ComparisonOptions.CaseInsensitive</api/language/comparisonoptions>`, `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">String</span> value with another <span class="title-ref">String</span> value. A non-empty <span class="title-ref">String</span> is always greater than an empty <span class="title-ref">String</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 `ComparisonOptions</api/language/comparisonoptions>`.CaseSensitive enum value to the *comparison* parameter.
>
> By default comparisons are done in an invariant locale (i.e. not dependent on the user's preferences). The `locale</api/os/locale>` parameter can be used to specify an explicit `locale</api/os/locale>` to do comparisons in.
>
> When the `locale</api/os/locale>` parameter is provided a more unicode-savvy lexical comparison is used at the expense of performance.
>
> A `RuntimeException</api/exceptions/runtimeexception>` will be raised when the specified options are invalid.
>
> Compare two <span class="title-ref">String</span> values:
>
> ``` xojo
> Var dog As String = "Dog"
> Var cat As String = "Cat"
>
> Var result As Integer
> result = dog.Compare(cat)
>
> ' result > 0
> ```

<div id="string.contains">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Contains

**Contains**(searchString As `String</api/data_types/string>`, options As `ComparisonOptions</api/language/comparisonoptions>` = `ComparisonOptions.CaseInsensitive</api/language/comparisonoptions>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As `Boolean</api/data_types/boolean>`

> Returns `True</api/language/true>` if the <span class="title-ref">string</span> contains the *searchString* considering the *options* and *locale* passed.
>
> Determine if the source <span class="title-ref">string</span> contains the <span class="title-ref">String</span> "Frodo":
>
> ``` xojo
> If article.Contains("Frodo") Then
> lordOfTheRingsReference = True
> End If
> ```

<div id="string.convertencoding">

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

</div>

<div class="rst-class">

forsearch

</div>

String.ConvertEncoding

**ConvertEncoding**(newEncoding As `TextEncoding</api/text/encoding_text/textencoding>`) As String

> Provides a quick way to convert a <span class="title-ref">String</span> of known encoding to some other encoding, without having to create a `TextConverter</api/text/encoding_text/textconverter>` object.
>
> When you need to write text to a file that will be opened by another app that expects a particular encoding, use ConvertEncoding to convert the text to that encoding before you call the Write method.
>
> The <span class="title-ref">String</span> must already have an encoding in order to convert it to something else. Use `DefineEncoding</api/text/encoding_text/defineencoding>` to set an encoding if it does not have one.
>
> The following code use the `Encodings</api/text/encoding_text/encodings>` module to convert the text in a `TextField</api/user_interface/desktop/desktoptextfield>` to the ANSI encoding:
>
> ``` xojo
> Var result As String
> result = TextField1.Text.ConvertEncoding(Encodings.WindowsANSI)
> ```
>
> Here is an example that converts the text in a `TextField</api/user_interface/desktop/desktoptextfield>` to the MacRoman encoding.
>
> ``` xojo
> Var f As FolderItem
> Var fileStream As TextOutputStream
> file = FolderItem.SaveFileDialog(FileTypes1.Text, "My Info.txt")
> If f <> Nil Then
> fileStream = TextOutputStream.Create(f)
> fileStream.Write(nameField.Text.ConvertEncoding(Encodings.MacRoman))
> fileStream.Close
> End If
> ```

<div id="string.countfields">

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

</div>

<div class="rst-class">

forsearch

</div>

String.CountFields

**CountFields**(separator As String) As `Integer</api/data_types/integer>`

> Returns the number of values (fields) in the <span class="title-ref">String</span> passed that are separated by the *separator* <span class="title-ref">String</span> passed. If the source <span class="title-ref">String</span> is binary data or you require case-sensitivity, use a `MemoryBlock</api/language/memoryblock>` instead.
>
> The CountFields function is useful for reading columns of data from a text file where the fields are separated with a specific character or characters.
>
> If the separator is not found within *stringVariable*, CountFields returns 1. If *stringVariable* is null, CountFields returns zero.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> Using CountFields in a loop to extract fields from a <span class="title-ref">String</span> is inefficient. You should use `ToArray<string.toarray>` and `Arrays.LastIndex<arrays.lastindex>` for this purpose.
>
> </div>
>
> The code below returns 5.
>
> ``` xojo
> Var count As Integer
> Var s As String
> s = "Dan*Smith*11/22/69*5125554323*Male"
> count = s.CountFields("*")
> ```
>
> The following code returns three because it counts the null "field" after the (unnecessary) final field delimiter.
>
> ``` xojo
> Var count As Integer
> Var s As String
>
> s = "Dan*Smith*"
> count = s.CountFields("*")
> ```
>
> This code in the `Opening<desktopcontrol.opening>` event handler populates a `PopupMenu</api/user_interface/desktop/desktoppopupmenu>` and sets the initial value to the current month:
>
> ``` xojo
> Var s As String
> Var i, last As Integer
> Var d As DateTime = DateTime.Now
>
> s = "January,February,March,April,May,June,July," _
>   + "August,September,October,November,December"
> last = s.CountFields(",")
>
> For i = 1 To last
>   Me.AddRow(s.NthField(",", i))
> Next
>
> Me.SelectedRowIndex = d.Month - 1
> ```

<div id="string.defineencoding">

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

</div>

<div class="rst-class">

forsearch

</div>

String.DefineEncoding

**DefineEncoding**(enc As `TextEncoding</api/text/encoding_text/textencoding>`) As String

> Returns a <span class="title-ref">String</span> with the same data as the given <span class="title-ref">String</span>, but with the encoding of the passed encoding.
>
> This function is useful when you have a <span class="title-ref">String</span> whose encoding is known to you but not to your application. The encoding of all strings created in your application is UTF-8, so you don't have to use DefineEncoding on them.
>
> Consult the values of *Base* entry for `TextEncoding</api/text/encoding_text/textencoding>` when creating the `TextEncoding</api/text/encoding_text/textencoding>` object using the `GetTextEncoding</api/text/encoding_text/gettextencoding>` function.
>
> The following code takes 8 bytes from a `MemoryBlock</api/language/memoryblock>` and sets the encoding to UTF16.
>
> ``` xojo
> Var source As String = MyMemoryBlock.StringValue(0, 8)
> TextField1.Text = source.DefineEncoding(Encodings.UTF16)
> ```
>
> This code uses DefineEncoding when reading text from a `TCPSocket</api/networking/tcpsocket>`.
>
> ``` xojo
> TextField1.Text = TCPSocket1.ReadAll.DefineEncoding(Encodings.UTF8)
> ```

<div id="string.endofline">

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

</div>

<div class="rst-class">

forsearch

</div>

String.EndOfLine

**EndOfLine** As `EndOfLine</api/text/endofline>`

> Returns the end of line character of the current OS.
>
> This is as shared method.

<div id="string.encoding">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Encoding

**Encoding** As `TextEncoding</api/text/encoding_text/textencoding>`

> Returns the text encoding of the passed <span class="title-ref">String</span>.
>
> This method does not attempt to "guess" the encoding of a <span class="title-ref">String</span>. It only returns the encoding of a <span class="title-ref">String</span> as it is known. Strings have a UTF-8 encoding by default. If you load data of another encoding into a <span class="title-ref">String</span> (from a file, perhaps), you will need to specify the encoding using `DefineEncoding</api/text/encoding_text/defineencoding>`.
>
> If the <span class="title-ref">String</span>'s encoding is unknown, Encoding returns `Nil</api/language/nil>`. Test whether the `TextEncoding</api/text/encoding_text/textencoding>` object is `Nil</api/language/nil>` or include an `Exception</api/exceptions/exception>` block if there is a chance the <span class="title-ref">String</span>'s encoding would not be known at runtime.
>
> ``` xojo
> Var f As FolderItem
> Var t As TextInputStream
> Var source As String
> Var enc As TextEncoding
> f = FolderItem.ShowOpenFileDialog("text") ' file type defined via the FileType class
> If f <> Nil Then
> t = TextInputStream.Open(f)
> source = t.ReadAll
> t.Close
> End If
>
> Try
> enc = source.Encoding ' This will be Encodings.UTF8
>
> ' If the file actually has text in a different encoding, then specify the
> ' encoding using DefineEncoding
> source = source.DefineEncoding(Encodings.UTF16LE)
>
> enc = source.Encoding ' This is now Encodings.UTF16LE
>
> Catch error As NilObjectException
> MessageBox(error.Message)
> End Try
> ```

<div id="string.endswith">

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

</div>

<div class="rst-class">

forsearch

</div>

String.EndsWith

**EndsWith**(value As String, options As `ComparisonOptions</api/language/comparisonoptions>` = `ComparisonOptions.CaseInsensitive</api/language/comparisonoptions>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As `Boolean</api/data_types/boolean>`

> Returns `True</api/language/true>` if the <span class="title-ref">String</span> ends with the *value* passed.
>
> EndsWith tells you whether or not the source <span class="title-ref">String</span> ends with the *value* passed based upon the comparison *options* (case-sensitive or case-insensitive) and *locale* specified.
>
> This example uses the EndsWith function determine if the source <span class="title-ref">String</span> ends with "Inc.":
>
> ``` xojo
> Var source As String
> source = "Xojo, Inc."
> If source.EndsWith("Inc.", ComparisonOptions.CaseSensitive, Locale.Current) Then
> System.Beep
> MessageBox("It ends with Inc.")
> End If
> ```

<div id="string.fromarray">

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

</div>

<div class="rst-class">

forsearch

</div>

String.FromArray

**FromArray**(fields() As String, delimiter As String = " ") As String

> Assigns a value to a <span class="title-ref">String</span> variable by concatenating the elements of a one-dimensional <span class="title-ref">String</span> array.
>
> This method is `shared</api/language/shared>`.
>
> *fields* is the array whose elements will be used to create result returned.
>
> The optional *delimiter* is used in separating the elements of *fields* when creating result. The default is one space.
>
> FromArray takes a one-dimensional <span class="title-ref">String</span> array and concatenates the individual elements into a single <span class="title-ref">String</span> variable. You can pass an optional delimiter which will be inserted between the fields in the resulting String. If no delimiter is passed, a single space will be used as the delimiter.
>
> The String.ToArray function performs the opposite function. It takes a <span class="title-ref">String</span> and creates an array by parsing the <span class="title-ref">string</span> into array elements using a specified delimiter.
>
> This example concatenates a three-element array into the <span class="title-ref">string</span> "Anthony,Aardvark,Accountant":
>
> ``` xojo
> Var names() As String = Array("Anthony", "Aardvark", "Accountant")
> Var combinedNames As String
> combinedNames = String.FromArray(names, ",") ' returns "Anthony,Aardvark,Accountant"
> ```

<div id="string.indexof">

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

</div>

<div class="rst-class">

forsearch

</div>

String.IndexOf

**IndexOf**(searchString As String, options As `ComparisonOptions</api/language/comparisonoptions>` = `ComparisonOptions.CaseInsensitive</api/language/comparisonoptions>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As `Integer</api/data_types/integer>`

> Returns the position of the first occurrence of a *searchString* inside the source <span class="title-ref">String</span>.
>
> If the *searchString* is not found within the source <span class="title-ref">String</span>, -1 is returned.
>
> IndexOf is case-insensitive by default, even with accented Roman and non-Roman characters. If you wish to make a case-sensitive search, use the optional `ComparisonOptions</api/language/comparisonoptions>` parameter.
>
> The *locale* As `Locale</api/os/locale>` parameter is required when the <span class="title-ref">String</span> contains non-Roman characters.
>
> This example uses the IndexOf function to locate the *searchString* within the source \`String\`:
>
> ``` xojo
> Var first As Integer
> Var source As String = "This is a test"
> first = source.IndexOf("t") ' returns 0
> first = source.IndexOf("is") ' returns 2
> first = source.IndexOf("tester") ' returns -1
> first = source.IndexOf("IS", ComparisonOptions.CaseSensitive) 'Returns -1
> ```
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> If you need to find the byte position of the *searchString* within the source <span class="title-ref">String</span>, use a `MemoryBlock</api/language/memoryblock>` instead.
>
> </div>

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

**IndexOf**(startPosition As `Integer</api/data_types/integer>`, searchString As String, options As `ComparisonOptions</api/language/comparisonoptions>` = `ComparisonOptions.CaseInsensitive</api/language/comparisonoptions>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As `Integer</api/data_types/integer>`

> Returns the position of the first occurrence after *startPosition* of *searchString* inside the source <span class="title-ref">String</span>. If *searchString* is an empty <span class="title-ref">String</span>, then *startPosition* is returned.
>
> The *locale* As `Locale</api/os/locale>` parameter is required when the <span class="title-ref">String</span> contains non-Roman characters.
>
> This example uses the IndexOf function to locate *searchString* within the source <span class="title-ref">String</span>.
>
> ``` xojo
> Var first As Integer
> Var source As String = "This is a test"
> first = source.IndexOf(4, "") 'Returns 4
> first = source.IndexOf(4, "is") 'Returns 5
> ```

<div id="string.indexofbytes">

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

</div>

<div class="rst-class">

forsearch

</div>

String.IndexOfBytes

**IndexOfBytes**(start As `Integer</api/data_types/integer>` = 0, find As String) As `Integer</api/data_types/integer>`

> Returns the byte position of the first occurrence of a <span class="title-ref">String</span> inside another <span class="title-ref">String</span>. The first character is numbered 0.
>
> If the find <span class="title-ref">String</span> is not found within the source <span class="title-ref">String</span>, -1 is returned. IndexOfBytes is essentially case-sensitive since it treats the <span class="title-ref">String</span> as a series of raw bytes. It should be used instead of `IndexOf<string.indexof>` when the <span class="title-ref">String</span> represents binary data.
>
> If you need to find the character position of the find <span class="title-ref">String</span> within the source <span class="title-ref">String</span>, use the `IndexOf<string.indexof>` function.
>
> This example uses the IndexOfBytes function to locate a <span class="title-ref">String</span> within another <span class="title-ref">String</span>.
>
> ``` xojo
> Var s As String = "This is a test"
> first = s.IndexOfBytes("test") ' returns 10
> ```

<div id="string.isempty">

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

</div>

<div class="rst-class">

forsearch

</div>

String.IsEmpty

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

> Returns `True</api/language/true>` if the <span class="title-ref">String</span> is empty.
>
> This is equivalent to `String.Bytes<string.bytes>` = 0.
>
> Check if the user entered data in a TextField:
>
> ``` xojo
> If TextField1.Text.IsEmpty Then
> MessageBox("Please enter a value in the field.")
> End If
> ```

<div id="string.isnumeric">

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

</div>

<div class="rst-class">

forsearch

</div>

String.IsNumeric

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

> Returns `True</api/language/true>` if the <span class="title-ref">string</span> is a valid number and `False</api/language/false>` if it is not.
>
> Strings greater than 127 characters always return `False</api/language/false>`.
>
> On Desktop and iOS targets, <span class="title-ref">String.IsNumeric</span> is locale-sensitive.
>
> In this example, IsNumeric is being used to inform the user the value they entered into a TextField is not a number:
>
> ``` xojo
> If TotalPayment.IsNumeric = False Then
> MessageBox("Please enter numbers only.")
> End If
> ```

<div id="string.lastfield">

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

</div>

<div class="rst-class">

forsearch

</div>

String.LastField

**LastField**(separator As String) As `String</api/data_types/string>`

> Returns the last field from a <span class="title-ref">String</span> of data. The first field is numbered 1. If you need to parse binary data, use a `MemoryBlock</api/language/memoryblock>` instead.
>
> The LastField function returns the last field value from the source based upon the *separator* passed.
>
> The *separator* may be a <span class="title-ref">String</span> of any length.
>
> If *separator* does not exist in the <span class="title-ref">String</span> then the entire <span class="title-ref">String</span> is returned.
>
> This example returns "Male"
>
> ``` xojo
> Var s, field As String
> s = "Dan*Smith*11/22/69*5125554323*Male"
> field = s.LastField("*")
> MessageBox(field)
> ```
>
> This example demonstrates the use of a multiple character separator.
>
> ``` xojo
> Var days As String = "Monday--Tuesday--Wednesday--Thursday--Friday--Saturday--Sunday"
> Var theDay As String = days.LastField("--") ' sets theDay to "Sunday"
> ```

<div id="string.left">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Left

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

> Returns the first *n* characters in a source <span class="title-ref">String</span>.
>
> In most cases, <span class="title-ref">Left</span> returns the number of visually distinct characters you request from the left side of the <span class="title-ref">String</span>. However, it may not when the <span class="title-ref">String</span> contains characters (such as emojis and characters from some written language character sets) each of which is a visually distinct single character but may require more than one [unit of storage](https://en.wikipedia.org/wiki/Code_point) per character.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> If you need to read bytes rather than characters, use the `MemoryBlock</api/language/memoryblock>` class.
>
> </div>
>
> This example returns the first five characters in a <span class="title-ref">String</span>.
>
> ``` xojo
> Var source As String = "Hello World"
> source = source.Left(5) ' returns "Hello"
> ```

<div id="string.leftbytes">

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

</div>

<div class="rst-class">

forsearch

</div>

String.LeftBytes

**LeftBytes**(count As `Integer</api/data_types/integer>`) As String

> Returns the first *count* bytes of the <span class="title-ref">String</span>.
>
> The LeftBytes function returns bytes from the source <span class="title-ref">String</span> starting from the left side (as the name implies). The encoding of the result is the same as the encoding of the source <span class="title-ref">String</span>.
>
> If you need to read the actual characters rather than bytes, use the `String</api/data_types/string>` function.
>
> This example uses the LeftBytes function to return the first 5 bytes from a <span class="title-ref">String</span>.
>
> ``` xojo
> Var s As String = "Hello World"
> s = s.LeftBytes(5) ' returns "Hello"
> ```

<div id="string.length">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Length

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

> Returns the number of characters in the specified <span class="title-ref">String</span>.
>
> In most cases, <span class="title-ref">Length</span> returns a value that is 1 for 1 to the number of visually distinct characters in the string. It will differ when the <span class="title-ref">String</span> contains characters (such as emojis and characters from some written language character sets) each of which is a visually distinct single character but may require more than one [unit of storage](https://en.wikipedia.org/wiki/Code_point) per character.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> If you need the number of bytes in the <span class="title-ref">String</span> rather than the number of characters, use the `Bytes<string.bytes>` function.
>
> </div>
>
> This example uses the Length function to return the number of characters in a <span class="title-ref">String</span>.
>
> ``` xojo
> Var s As String
> s = "Hello World"
> n = s.Length ' returns 11
> ```

<div id="string.lowercase">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Lowercase

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

> Returns the source <span class="title-ref">String</span> with all characters converted to lowercase.
>
> Returns the value with all alphabetic characters in lowercase.
>
> The *locale* As `Locale</api/os/locale>` parameter is required when the <span class="title-ref">String</span> contains non-Roman characters.
>
> The examples below convert the value passed to lowercase.
>
> ``` xojo
> Var result As String
> Var source As String = "tHe Quick fOX"
> result = source.Lowercase ' returns "the quick fox"
>
> source = "THE 5 LAZY DOGS"
> result = source.Lowercase ' returns "the 5 lazy dogs"
> ```
>
> This example demonstrates how Lowercase with Locale applies Turkish-specific casing rules, converting "I" to dotless "ı".
>
> ``` xojo
> ' Test Turkish locale
> Var tr As New Locale("tr_TR")
> Var upper As String = "FILE"
>
> ' Without specifying a locale, the result depends on the system locale.
> ' In most locales, this returns "file".
> Var lowerResult As String = upper.Lowercase
>
> ' In Turkish, uppercase "I" maps to lowercase dotless "ı",
> ' so the expected result is "fıle".
> Var lowerResultInTurkish As String = upper.Lowercase(tr)
> ```

<div id="string.middle">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Middle

<div class="rst-class">

forsearch

</div>

Middle

**Middle**(index As `Integer</api/data_types/integer>`, `Optional</api/language/optional>` length As `Integer</api/data_types/integer>`) As String

> Returns a portion of a <span class="title-ref">String</span>. The first character is numbered 0.
>
> To determine the number of characters in a <span class="title-ref">String</span>, use the `Length<string.length>` function.
>
> In most cases, <span class="title-ref">Middle</span> returns the number of visually distinct characters you request from the *index* position of the <span class="title-ref">String</span>. However, it may not when the <span class="title-ref">String</span> contains characters (such as emojis and characters from some written language character sets) each of which is a visually distinct single character but may require more than one [unit of storage](https://en.wikipedia.org/wiki/Code_point) per character.
>
> These examples use the Middle function to return portions of a <span class="title-ref">String</span>.
>
> ``` xojo
> Var result As 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 <span class="title-ref">String</span> in TextField1 to hex and writes the result to TextField2:
>
> ``` xojo
> TextField2.Text = ""
> For i As Integer = 1 To TextField1.Text.Length
> TextField2.Text = TextField2.Text + "&h" + Hex(TextField1.Text.Middle(i, 1).Asc)
> Next
> ```

<div id="string.middlebytes">

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

</div>

<div class="rst-class">

forsearch

</div>

String.MiddleBytes

**MiddleBytes**(start As `Integer</api/data_types/integer>`, `Optional</api/language/optional>` length As `Integer</api/data_types/integer>`) As String

> Returns a portion of a <span class="title-ref">String</span>. The first character is numbered 0.
>
> MiddleBytes treats *source* as a series of bytes, rather than a series of characters. MiddleBytes should be used when *source* represents binary data. The encoding of the result is the same as the encoding of the source <span class="title-ref">String</span>.
>
> If you need to extract characters rather than bytes, use the `Middle<string.middle>` function. To determine the number of bytes in a <span class="title-ref">String</span>, use the `Bytes<string.bytes>` function.
>
> These examples use the MiddleBytes function to return portions of a <span class="title-ref">String</span>.
>
> ``` xojo
> Var s As String = "This is a test"
> s = s.MiddleBytes(10, 4) ' returns "test"
> ```

<div id="string.nthfield">

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

</div>

<div class="rst-class">

forsearch

</div>

String.NthField

**NthField**(separator As String, fieldNumber As `Integer</api/data_types/integer>`) As String

> Returns a field from a <span class="title-ref">String</span> of data. The first field is numbered 1. If you need to parse binary data, use a `MemoryBlock</api/language/memoryblock>` instead.
>
> The NthField function returns the field value from the source that precedes the *fieldNumber* occurrence of the *separator* in the source.
>
> The *separator* may be a <span class="title-ref">String</span> of any length.
>
> If *fieldNumber* is out of bounds, an empty <span class="title-ref">String</span> is returned. NthField is not case-sensitive.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> Using NthField in a loop to extract fields from a <span class="title-ref">String</span> is inefficient. You should use `ToArray<string.toarray>` for this purpose.
>
> </div>
>
> This example returns "Smith"
>
> ``` xojo
> Var s, field As String
> s = "Dan*Smith*11/22/69*5125554323*Male"
> field = s.NthField("*", 2)
> MessageBox(field)
> ```
>
> This example demonstrates the use of a multiple character separator.
>
> ``` xojo
> Var days As String = "Monday--Tuesday--Wednesday--Thursday--Friday--Saturday--Sunday"
> Var theDay As String = days.NthField("--", 3)  ' sets theDay to "Wednesday"
> ```

<div id="string.replace">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Replace

**Replace**(substring As String, replacementString As String) As String

> Replaces the first occurrence of a <span class="title-ref">String</span> with another <span class="title-ref">String</span>.
>
> Replaces the first occurrence of *substring* in *sourceString* with *replacementString*. Replace is case-insensitive.
>
> If *replacementString* is an empty <span class="title-ref">String</span> (""), the Replace function deletes the first occurrence of the *substring* in the *sourceString*.
>
> If *substring* is an empty <span class="title-ref">String</span> (""), the Replace function returns an unchanged copy of the *sourceString*.
>
> Below are some examples that show the results of the Replace function:
>
> ``` xojo
> Var result As String
> Var source As String = "the quick fox"
> result = source.Replace("fox", "rabbit") ' returns "The quick rabbit"
> result = source.Replace("f", "b") ' returns "The quick box"
> result = source.Replace("quick ", "") ' returns "The fox"
> ```

<div id="string.replaceall">

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

</div>

<div class="rst-class">

forsearch

</div>

String.ReplaceAll

**ReplaceAll**(substring As String, replacementString As String) As String

> Replaces all occurrences of a <span class="title-ref">String</span> with another <span class="title-ref">String</span>.
>
> The ReplaceAll function replaces all occurrences of *substring* in the original <span class="title-ref">String</span> with *replacementString*. ReplaceAll is case-insensitive.
>
> If *replacementString* is an empty <span class="title-ref">String</span> (""), the ReplaceAll function deletes every occurrence of the *substring* in the original <span class="title-ref">String</span>.
>
> If *substring* is an empty <span class="title-ref">String</span> (""), the ReplaceAll function returns an unchanged copy of the original <span class="title-ref">String</span>.
>
> Below are some examples that show the results of the ReplaceAll function
>
> ``` xojo
> Var result As String
> Var source As String = "xyxyxy"
> result = source.ReplaceAll("x", "z") ' returns "zyzyzy"
>
> source = "the quick fox"
> result = source.ReplaceAll(" ", "") ' returns "Thequickfox"
>
> source = "the quick fox"
> result = source.ReplaceAll(" ", ", ")  ' returns "the, quick, fox"
> ```

<div id="string.replaceallbytes">

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

</div>

<div class="rst-class">

forsearch

</div>

String.ReplaceAllBytes

**ReplaceAllBytes**(substring As String, replacementString As String) As String

> Replaces all occurrences of a <span class="title-ref">String</span> with another <span class="title-ref">String</span>.
>
> The ReplaceAllBytes function replaces all occurrences of *substring* in *sourceString* with *newString*. ReplaceAllBytes is case-sensitive because it treats the source <span class="title-ref">String</span> as a series of raw bytes.
>
> If *replacementString* is an empty <span class="title-ref">String</span> (""), the ReplaceAllBytes function deletes every occurrence of the *substring* in the *sourceString*.
>
> If *substring* is an empty <span class="title-ref">String</span> (""), the ReplaceAllBytes function returns an unchanged copy of the *sourceString*.
>
> ReplaceAllBytes is case-sensitive; it treats *sourceString* as a series of raw bytes. It should be used instead of `ReplaceAll<string.replaceall>` when the <span class="title-ref">String</span> represents a series of bytes or when your application will run in a one-byte character set (such as the US system) and you want case-sensitivity.
>
> Below are some examples that show the results of the ReplaceAll function
>
> ``` xojo
> Var result As String
> Var source As String = "xyxyxy"
> result = source.ReplaceAllBytes("x", "z") ' returns "zyzyzy"
>
> source = "The quick fox"
> result = source.ReplaceAllBytes(" ", "") ' returns "Thequickfox"
>
>
> source = "The Quick Fox"
> result = source.ReplaceAllBytes(" ", ", ")  ' returns "The, Quick, Fox"
> ```

<div id="string.replacebytes">

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

</div>

<div class="rst-class">

forsearch

</div>

String.ReplaceBytes

**ReplaceBytes**(substring As String, replacementString As String) As String

> Replaces the first occurrence of a <span class="title-ref">String</span> with another <span class="title-ref">String</span>.
>
> Replaces the first occurrence of *substring* in *sourceString* with *replacementString*. ReplaceBytes is the byte version of `Replace<string.replace>`.
>
> If *replacementString* is an empty <span class="title-ref">String</span> (""), the ReplaceBytes function deletes the first occurrence of the *substring* in the *sourceString*.
>
> If *substring* is an empty <span class="title-ref">String</span> (""), the ReplaceBytes function returns an unchanged copy of *sourceString*.
>
> ReplaceBytes is case-sensitive; it treats *sourceString* as a series of raw bytes. It should be used instead of `Replace<string.replace>` when the <span class="title-ref">String</span> represents a series of bytes or when your application will run in a one-byte character set (such as the US system) and you want case-sensitivity.
>
> Below are some examples that show the results of the ReplaceBytes function:
>
> ``` xojo
> Var result As String
> result = ReplaceBytes("The quick fox", "fox", "rabbit") ' returns "The quick rabbit"
> result = ReplaceBytes("The quick fox", "f", "b") ' returns "The quick box"
> result = ReplaceBytes("The quick fox", "quick ", "") ' returns "The fox"
> ```
>
> Using the second syntax:
>
> ``` xojo
> Var result, s As String
> s = "The quick fox"
> result = s.ReplaceBytes("fox", "rabbit") ' returns "The quick rabbit"
> ```

<div id="string.replacelineendings">

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

</div>

<div class="rst-class">

forsearch

</div>

String.ReplaceLineEndings

**ReplaceLineEndings**(replacement As String) As String

> Replaces the line endings in the passed <span class="title-ref">String</span> with the specified *replacement*.
>
> ReplaceLineEndings does a global search-and-replace for the end of line characters in *SourceString* using the specified value (*replacement*) as the replacement <span class="title-ref">String</span>. The search automatically recognizes Windows, macOS, and Unix line endings. Use this function to make multiline (or multi-paragraph) text compatible across platforms. The easiest way to specify the replacement value is with the `EndOfLine</api/text/endofline>` class.
>
> This example replaces the line endings in the text in a `TextField</api/user_interface/desktop/desktoptextfield>` with Windows line endings.
>
> ``` xojo
> Var s As String
> s = TextField1.Text.ReplaceLineEndings(EndOfLine.Windows)
> ```
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> Replacing Unicode new line characters is not supported.
>
> </div>

<div id="string.right">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Right

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

> Returns the last n characters from the <span class="title-ref">String</span> specified.
>
> In most cases, <span class="title-ref">Right</span> returns the number of visually distinct characters you request from the right side of the <span class="title-ref">String</span>. However, it may not when the <span class="title-ref">String</span> contains characters (such as emojis and characters from some written language character sets) each of which is a visually distinct single character but may require more than one [unit of storage](https://en.wikipedia.org/wiki/Code_point) per character.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> If you need to read bytes rather than characters, use the `MemoryBlock</api/language/memoryblock>` class.
>
> </div>
>
> This example uses the Right function to return the last 5 characters from a \`String\`:
>
> ``` xojo
> Var result As String
> Var source As String = "Hello World"
> result = source.Right(5) ' returns "World"
> ```

<div id="string.rightbytes">

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

</div>

<div class="rst-class">

forsearch

</div>

String.RightBytes

**RightBytes**(count As `Integer</api/data_types/integer>`) As String

> Returns the last *count* bytes from the <span class="title-ref">String</span>.
>
> The RightBytes function returns bytes from the source <span class="title-ref">String</span> starting from the right side (as the name implies). The encoding of the result is the same as the encoding of the source <span class="title-ref">String</span>.
>
> RightBytes treats *source* as a series of bytes rather than a series of characters. It should be used when the <span class="title-ref">String</span> represents binary data. If you need to read characters rather than bytes, use the `String</api/data_types/string>` function.
>
> This example uses the RightBytes function to return the last 5 bytes from a <span class="title-ref">String</span>.
>
> ``` xojo
> Var s As String = "Hello World"
> s = s.RightBytes(5) ' returns "World"
> ```

<div id="string.split">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Split

<div class="rst-class">

forsearch

</div>

Split

**Split**(delimiter As String = " ") As String()

> Creates a one-dimensional array from the <span class="title-ref">String</span>.
>
> Use the Split function to create a new <span class="title-ref">String</span> array from a list of elements (or fields) that are separated by a *delimiter*. If the optional parameter, *delimiter*, is not passed, a single space is assumed as the delimiter. If the *delimiter* is an empty <span class="title-ref">String</span>, the source <span class="title-ref">String</span> is split into characters.
>
> Split works exactly the same as `ToArray<string.toarray>`.
>
> If the <span class="title-ref">String</span> does not contain the delimiter, the array returned will be empty.
>
> The section of code specifies the comma delimiter and the second uses the default delimiter. They place each field into an array element, producing a three-element array. The last code section parses the <span class="title-ref">String</span> into individual characters.
>
> ``` xojo
> Var anArray() As String
> Var s As String
> s = "Adam,Aardvark,Accountant"
> anArray = s.Split(",") ' produces 3-element array
> anArray = s.Split("") ' produces array of individual characters
> ```

<div id="string.splitbytes">

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

</div>

<div class="rst-class">

forsearch

</div>

String.SplitBytes

**SplitBytes**(delimiter As String = " ") As String()

> Creates a one-dimensional array from the <span class="title-ref">String</span> passed. This method is identical to `Split<string.split>`, except that it treats the source as binary data.
>
> This function is intended for use with binary data. It can be used with normal encoded <span class="title-ref">String</span> data, but may not work as expected with some Japanese multibyte encodings.
>
> ``` xojo
> Var anArray() As String
> Var s As String = "Adam,Aardvark,Accountant"
> anArray = s.SplitBytes(",") ' produces 3-element array
> anArray = s.SplitBytes("") ' produces array of individual characters, but should be avoided for some encodings such as Japanese
> ```

<div id="string.titlecase">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Titlecase

**Titlecase**(locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As String

> Returns the <span class="title-ref">String</span> passed to it with all alphabetic characters in Titlecase.
>
> Converts all characters in a <span class="title-ref">String</span> to lowercase characters and then converts the first character of each word to uppercase. Specifically, the first character in the string as well as the first character following a whitespace. Numbers are not affected.
>
> The *locale* As `Locale</api/os/locale>` parameter is required when the <span class="title-ref">String</span> contains non-Roman characters.
>
> The example below converts the values passed to Titlecase
>
> ``` xojo
> Var result As String
> Var source As String = "tHe Quick fOX"
> result = source.Titlecase ' returns "The Quick Fox"
> source = "THE LAZY DOG"
> result = source.Titlecase ' returns "The Lazy Dog"
> ```
>
> This example demonstrates how Titlecase with Locale applies Azerbaijani casing rules when capitalizing words.
>
> ``` xojo
> ' Test Azerbaijani locale
> Var az As New Locale("az_AZ")
> Var text As String = "ilham əliyev"
>
> ' Without specifying a locale, this usually returns "Ilham  Əliyev".
> Var titleDefault As String = text.Titlecase
>
> ' In Azerbaijani, the first letter "i" becomes "İ" (with dot),
> ' so the expected result is "İlham  Əliyev".
> Var titleAzeri As String = text.Titlecase(az)
> ```

<div id="string.toarray">

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

</div>

<div class="rst-class">

forsearch

</div>

String.ToArray

**ToArray**(delimiter As String = " ") As String()

> Creates a one-dimensional array from the <span class="title-ref">String</span>.
>
> Use the ToArray function to create a new <span class="title-ref">String</span> array from a list of elements (or fields) that are separated by a *delimiter*. If the optional parameter, delimiter, is not passed, a single space is assumed as the delimiter. If the delimiter is an empty <span class="title-ref">String</span>, an array of characters is created from the source <span class="title-ref">String</span>.
>
> ToArray works exactly the same as `Split<string.split>`.
>
> The section of code specifies the comma delimiter and the second uses the default delimiter. They place each field into an array element, producing a three-element array. The last code section parses the <span class="title-ref">String</span> into individual characters.
>
> ``` xojo
> Var anArray(-1) As String
> Var s As String
> s = "Adam,Aardvark,Accountant"
> anArray = s.ToArray(",") ' produces 3-element array
> anArray = s.ToArray("") ' produces array of individual characters
> ```
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> If the delimiter does not exist in the source <span class="title-ref">String</span>, an array with a single element containing the source string is returned.
>
> </div>
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> If the source <span class="title-ref">String</span> is empty, `ToArray` returns an empty array with no elements, even if a *delimiter* is specified.
>
> </div>

<div id="string.toboolean">

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

</div>

<div class="rst-class">

forsearch

</div>

String.ToBoolean

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

> Returns `True</api/language/true>` if the <span class="title-ref">String</span> is `1` or `True` or `False</api/language/false>` if it is any other value.

<div id="string.todouble">

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

</div>

<div class="rst-class">

forsearch

</div>

String.ToDouble

**ToDouble** As `Double</api/data_types/double>`

> Returns the numeric equivalent of the source <span class="title-ref">String</span> using the User's system settings for hundreds and decimal separators.
>
> ToDouble should be used for numeric values that will be visible to the user. For purely internal values, the `Val</api/text/val>` function can be used as it does not support the user's system settings.
>
> ToDouble returns zero if <span class="title-ref">String</span> contains no numbers, except in the special case where the <span class="title-ref">String</span> begins with the <span class="title-ref">String</span> “NAN”. In this case, it returns "NAN(021)".
>
> Numbers are converted only if they are found at the beginning of the <span class="title-ref">String</span>. Any numbers that follow a non-numeric value are ignored.
>
> So,
>
> - "1AA2" returns 1
> - "AA2" returns 0
> - "12AA54" returns 12
>
> This code use the ToDouble function to return the numbers contained in a <span class="title-ref">String</span>.
>
> ``` xojo
> Var source As String
> Var result As Double
>
> source = "12345"
> result = source.ToDouble  ' returns 12345
>
> source = "54.05car45"
> result = source.ToDouble ' returns 54.05
>
> source = "123.45"
> result = source.ToDouble ' returns 123.45
>
> source = "123 45"
> result = source.ToDouble ' returns 123
>
> source = "123,456"
> result = source.ToDouble ' returns 123456
>
> source = "auto"
> result = source.ToDouble ' returns 0
>
> source = "&hFFF"
> result = source.ToDouble  ' returns 4095
>
> source = "&b1111"
> result = source.ToDouble  ' returns 15
> ```

<div id="string.toint64">

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

</div>

<div class="rst-class">

forsearch

</div>

String.ToInt64

**ToInt64** As `Int64</api/data_types/additional_types/int64>`

> Returns the numeric form of a <span class="title-ref">String</span> as an `Int64</api/data_types/additional_types/int64>`.
>
> The ToInt64 function stops reading the <span class="title-ref">String</span> at the first character it doesn't recognize as part of a number. All other characters are automatically stripped.
>
> Prefixes including `&o</api/language/literals/o>` (octal), `&b</api/language/literals/b>` (binary), and `&h</api/language/literals/h>` (hexadecimal) are recognized. However, spaces are not allowed in front of the ampersand. For example, `& hFF</api/language/literals/h>` returns 0, while `&hFF</api/language/literals/h>` returns 255.
>
> ToInt64 returns zero if *string* contains no numbers.
>
> This code use the ToInt64 function to return the numbers contained in a <span class="title-ref">String</span> literal or a <span class="title-ref">String</span> variable:
>
> ``` xojo
> Var result As Int64
> Var source As String = "12345"
> result = source.ToInt64 ' returns 12345
>
> source = " 12345"
> result = source.ToInt64 ' returns 12345
>
> source = "123 45"
> result = source.ToInt64 ' returns 123
>
> source = "&hFFF"
> result = source.ToInt64 ' returns 4095
>
> source = "& hFFF"
> result = source.ToInt64 ' returns 0
>
> source = "&b1111"
> result = source.ToInt64 ' returns 15
> ```

<div id="string.tointeger">

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

</div>

<div class="rst-class">

forsearch

</div>

String.ToInteger

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

> Returns the integer equivalent of the source <span class="title-ref">String</span>. This function is the same as the `Val</api/text/val>` function but is international-savvy.
>
> For localized number formatting, use the `Integer.FromString<integer.fromstring>` function instead. Generally, you will use `Val</api/text/val>` for converting internal data and use `ToInteger<string.tointeger>` for converting data for input and output of user data.
>
> ToInteger returns zero if <span class="title-ref">String</span> contains no numbers, except in the special case where the <span class="title-ref">String</span> begins with the <span class="title-ref">String</span> “NAN”. In this case, it returns "NAN(021)".
>
> Numbers are converted only if they are found at the beginning of the <span class="title-ref">String</span>. Any numbers that follow a non-numeric value are ignored.
>
> So,
>
> - "1AA2" returns 1
> - "AA2" returns 0
> - "12AA54" returns 12
>
> This code use the ToInteger function to return the numbers contained in a <span class="title-ref">String</span>.
>
> ``` xojo
> Var source As String
> Var result As Integer
>
> source = "12345"
> result = source.ToInteger  ' returns 12345
>
> source = "54.05car45"
> result = source.ToInteger ' returns 54
>
> source = "123.45"
> result = source.ToInteger ' returns 123
>
> source = "123 45"
> result = source.ToInteger ' returns 123
>
> source = "123,456"
> result = source.ToInteger ' returns 123
>
> source = "auto"
> result = source.ToInteger ' returns 0
>
> source = "&hFFF"
> result = source.ToInteger  ' returns 4095
>
> source = "&b1111"
> result = source.ToInteger  ' returns 15
> ```

<div id="string.trim">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Trim

**Trim**(`Optional</api/language/optional>` `ParamArray</api/language/paramarray>` characters() As String) As String

> Returns the <span class="title-ref">String</span> passed with either whitespaces or the *characters* passed removed from the beginning and ending of the <span class="title-ref">String</span>.
>
> Unless specific characters are passed in, Trim trims [whitespace characters as defined by unicode](http://www.unicode.org/Public/UNIDATA/PropList.txt).
>
> This example removes the whitespaces from either side of the <span class="title-ref">String</span> passed:
>
> ``` xojo
> Var source as String = "    Hello World   "
> Var result as String = source.Trim ' Returns "Hello World"
> ```
>
> This example removes \*, and % from the beginning and ending of the <span class="title-ref">String</span> passed:
>
> ``` xojo
> Var source as String = "**Hello World%%"
> Var result as String = source.Trim("*", "%") ' Returns "Hello World"
> ```
>
> This example trims the div tags from an HTML \`String\`:
>
> ``` xojo
> Var source As String = "<div>Hello World</div>"
> Var result As String = source.Trim("<div>","</div>") ' Returns "Hello World"
> ```

<div id="string.trimleft">

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

</div>

<div class="rst-class">

forsearch

</div>

String.TrimLeft

**TrimLeft**(`Optional</api/language/optional>` `ParamArray</api/language/paramarray>` characters() As String) As String

> Returns the <span class="title-ref">String</span> passed with either whitespaces or the *characters* passed removed from the left side of the <span class="title-ref">String</span>.
>
> Unless specific characters are passed in, TrimLeft trims [whitespace characters as defined by unicode](http://www.unicode.org/Public/UNIDATA/PropList.txt).
>
> This example removes the whitespaces from the left side of the <span class="title-ref">String</span> passed:
>
> ``` xojo
> Var source As String = "   Hello World   "
> Var result As String
> result = source.TrimLeft ' Returns "Hello World  "
> ```
>
> This example removes \* from the left side of the <span class="title-ref">String</span> passed:
>
> ``` xojo
> Var source as String = "*Hello World*"
> Var result as String = source.TrimLeft("*") ' Returns "Hello World*"
> ```

<div id="string.trimright">

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

</div>

<div class="rst-class">

forsearch

</div>

String.TrimRight

**TrimRight**(`Optional</api/language/optional>` `ParamArray</api/language/paramarray>` characters() As String) As String

> Returns the <span class="title-ref">String</span> passed with either whitespaces or the *characters* passed removed from the right side of the <span class="title-ref">String</span>.
>
> Unless specific characters are passed in, TrimRight trims [whitespace characters as defined by unicode](http://www.unicode.org/Public/UNIDATA/PropList.txt).
>
> This example removes the whitespaces from the right side of the <span class="title-ref">String</span> passed:
>
> ``` xojo
> Var source As String = "   Hello World   "
> Var result As String
> result = source.TrimRight ' Returns "  Hello World"
> ```
>
> This example removes \* from the right side of the <span class="title-ref">String</span> passed:
>
> ``` xojo
> Var source as String = "*Hello World*"
> Var result as String = source.TrimRight("*") ' Returns "*Hello World"
> ```

<div id="string.uppercase">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Uppercase

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

> Returns the source <span class="title-ref">String</span> with all characters converted to uppercase.
>
> Returns the <span class="title-ref">String</span> with all alphabetic characters in uppercase.
>
> The *locale* As `Locale</api/os/locale>` parameter is required when the <span class="title-ref">String</span> contains non-Roman characters.
>
> The example below converts the value passed to uppercase.
>
> ``` xojo
> Var result As String
> Var source As String = "tHe Quick fOX"
> result = source.Uppercase ' returns "THE QUICK FOX"
>
> source = "the 5 lazy dogs"
> result = source.Uppercase ' returns "THE 5 LAZY DOGS"
> ```
>
> This example shows how Uppercase with Locale converts "i" to "İ" (capital I with dot) in Azerbaijani.
>
> ``` xojo
> ' Test Azerbaijani locale
> Var az As New Locale("az_AZ")
> Var text As String = "istanbul"
>
> ' Without specifying a locale, this usually returns "ISTANBUL".
> Var upperDefault As String = text.Uppercase
>
> ' In Azerbaijani, lowercase "i" maps to uppercase "İ" (with dot),
> ' so the expected result is "İSTANBUL".
> Var upperAzeri As String = text.Uppercase(az)
> ```

<div id="string.val">

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

</div>

<div class="rst-class">

forsearch

</div>

String.Val

**Val** As `Double</api/data_types/double>`

> Returns the numeric form of a <span class="title-ref">String</span>, always using US/English notation. For any user-visible numbers, you should use `ToDouble<string.todouble>` instead.
>
> Val recognizes prefixes `&o</api/language/literals/o>` (octal), `&b</api/language/literals/b>` (binary), and `&h</api/language/literals/h>` (hexadecimal). However, spaces are not allowed in front of the ampersand. That is, " &hFF" returns 255, but "&h FF" returns 0.
>
> For localized number formatting, use the `ToDouble<string.todouble>` function instead. Generally, you will use Val for converting internal data and use `ToDouble<string.todouble>` for converting data for input and output of user data.
>
> It is important to note that *Val* does not take separator characters into consideration. For example:
>
> ``` xojo
> Var d As Double
> d = Val("10,000.95") ' The "," causes the string to stop being converted
> ```
>
> returns 10. Use `ToDouble<string.todouble>` for data that is from the user as it may contain such characters. `ToDouble<string.todouble>` handles imbedded separators in the input <span class="title-ref">String</span>.
>
> Val returns zero if the <span class="title-ref">String</span> contains no numbers, except in the special case where the <span class="title-ref">String</span> begins with the <span class="title-ref">String</span> "NAN". In this case, it returns "NAN(021)".
>
> As Val converts the <span class="title-ref">String</span> to a double, large integer values in a <span class="title-ref">String</span> could exceed the maximum integer value that a double can hold. In these cases, use `ToInt64<string.toint64>` to convert longer integer strings to Int64 values.
>
> Numbers are converted only if they are found at the beginning of the <span class="title-ref">String</span>. Any numbers that follow a non-numeric value are ignored.
>
> So,
>
> - "1AA2" returns 1
> - "AA2" returns 0
> - "12AA54" returns 12
>
> These examples use the Val function to return the numbers contained in a <span class="title-ref">String</span>.
>
> ``` xojo
> Var n As Double
>
> n = Val("12345") ' returns 12345
> n = Val("54.25car45") ' returns 54.25
> n = Val("123.25") ' returns 123.25
> n = Val("123 25") ' returns 123
> n = Val("123,456") ' returns 123
> n = Val("auto") ' returns 0
> n = Val("&hFFF") ' returns 4095
> n = Val("&b1111") ' returns 15
>
> Var s As String = "12345"
>
> n = s.Val ' returns 12345
> ```
>
> Val also supports exponent notation:
>
> ``` xojo
> Var s As String
> Var n As Double
>
> s = "1.0e-2"
> n = s.Val ' returns 0.01
>
> s = "1.0e4"
> n = s.Val ' returns 10000
> ```

## Notes

Any kind of alphabetic or numeric information can be stored as a <span class="title-ref">String</span>. "Jean Marie", "3/17/98", "45.90" are all examples of strings. When you place quotes around information in your code, you are indicating the data as just a series of characters and nothing more. The maximum length of a <span class="title-ref">String</span> is limited only by available memory. The default value of a <span class="title-ref">String</span> is "".

All computers use encoding schemes to store character strings as a series of bytes. The oldest and most familiar encoding scheme is the ASCII encoding. It defines character codes only for values 0-127. These values include only the upper and lowercase English alphabet, numbers, some symbols, and invisible control codes used in early computers.

Many extensions to ASCII have been introduced which handle additional symbols, accented characters, non-Roman characters, and so forth. In particular, the Unicode encoding is designed to handle any language and a mixture of languages in the same <span class="title-ref">String</span>. Two different Unicode formats are supported: UTF-8 and UTF-16. Your constants, <span class="title-ref">String</span> literals, and so forth are nearly always stored internally using UTF-8 encoding.

If the strings you work with are created, saved, and read within your code, you shouldn't have to worry about encoding issues because the encoding is stored along with the content of the <span class="title-ref">String</span>.

Since character codes above 127 represent different characters in different encoding schemes, it is important that you understand the encoding that is used for strings that were generated outside of your app. When you read in a text <span class="title-ref">String</span> using the TextInputStream class, set the Encoding property to the correct encoding or use the optional Encoding parameter of the Read, ReadLine, or ReadAll methods. You can determine the encoding of a <span class="title-ref">String</span> using the Encoding function. If you need to save <span class="title-ref">String</span> data in a particular encoding, use the ConvertEncoding function. Specify the desired encoding using the Encodings module.

If you need to get a character that corresponds to the value of a character code, use the Chr function only if it is an ASCII code. In other cases, it is best to use the Chr method of the TextEncoding class. This enables you to specify both the encoding scheme and the desired character code.

The `VarType</api/language/vartype>` function returns 8 when passed a <span class="title-ref">String</span>.

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

### Iterating through characters

If you need to access each character of a <span class="title-ref">String</span> but don't need to know the index of that character, you can use an iterator:

``` xojo
Var wizard As String = "Gandalf"
For Each letter As String In wizard.Characters
  MessageBox(letter)
Next
```

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

### Converting from the text type

Text values automatically convert to <span class="title-ref">String</span> (with UTF8 encoding) when assigned:

``` xojo
Var t As Text = "Hello, World!"
Var s As String = t
```

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

### Empty does not equal nil

Despite an empty <span class="title-ref">String</span> contains nothing, such <span class="title-ref">String</span> is not equivalent to `Nil</api/language/nil>`. `Nil</api/language/nil>` represents a non-existing object, whereas an empty <span class="title-ref">String</span> is an existing object even if it is empty.

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

### Including double quotes

If you need to include a double quote mark inside your <span class="title-ref">String</span> literal, you can do it by typing two consecutive double quote marks. For example, a sentence like *He told me "yes"* can be typed in as a <span class="title-ref">String</span> literal as:

``` xojo
Var s As String = "He told me ""yes"""
```

Following the same logic, the literal *""""* actually represents a single double quote character (the first and last double quotes denote a <span class="title-ref">String</span> literal and the 2 consecutive double quotes in-between represents a double quote character).

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

### The ampersand (&) character

Be aware that a single ampersand (&) character will often be interpreted as a keyboard shortcut if you are using your <span class="title-ref">String</span> literal inside the user interface, e.g. if you use your <span class="title-ref">String</span> literal as a button caption, a menu item… This behavior is aimed at implementing keyboard shortcuts (a.k.a. keyboard accelerators) on Microsoft Windows operating system. As a consequence, you may need to use "&&" instead of a single "&" character in some cases.

Escaping a character using the backslash (\\ character \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

If a <span class="title-ref">String</span> is prefixed with the \\ character, it will be treated as a C string literal and thus [all standard string literal rules](https://en.wikipedia.org/wiki/String_literal) will apply.

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

### Unicode homoglyphs and string comparison

When comparing strings with the `=` operator, Xojo compares Unicode [codepoints](https://en.wikipedia.org/wiki/Code_point), not visual appearance. This means two strings can appear identical on screen yet not be equal because their characters come from different Unicode blocks and have different codepoint values.

For example, the Latin letter "A" (U+0041) and the Cyrillic letter "А" (U+0410) are pixel-for-pixel identical in most fonts, but they are not equal:

``` xojo
Var latinA As String = "A"    ' Latin A, codepoint 65
Var cyrillicA As String = "А" ' Cyrillic А, codepoint 1040

If latinA = cyrillicA Then
    ' This will NOT execute
End If
```

To inspect the actual codepoints of a <span class="title-ref">String</span>, use the `Codepoints<string.codepoints>` method:

``` xojo
For Each cp As Integer In cyrillicA.Codepoints
    MessageBox(cp.ToString) ' Displays 1040
Next
```

<div class="note">

<div class="title">

Note

</div>

Characters that look identical but have different codepoints are called [homoglyphs](https://en.wikipedia.org/wiki/Homoglyph). They can cause subtle bugs when strings originate from external sources such as user input, files, or network data, and are sometimes exploited in security attacks that use look-alike characters to impersonate legitimate identifiers.

</div>

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

## Sample code

``` xojo
Var s As String
s = "Hello, World!"
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`-</api/language/operators/mathematical/->`, `+</api/language/operators/mathematical/+>`, `*</api/language/operators/mathematical/x>`, `/</api/language/operators/mathematical/division>`, `<</api/language/operators/comparison/less_than>`, `\<=</api/language/operators/comparison/less_than_or_equal>`, `=</api/language/operators/comparison/equals_operator>`, `\>=</api/language/operators/comparison/greater_than_or_equal>`, `\></api/language/operators/comparison/greater_than>`, `<></api/language/operators/comparison/not_equal>` operators; `&u</api/language/literals/u>` literal; `ConvertEncoding</api/text/encoding_text/convertencoding>`, `IsNumeric</api/language/isnumeric>`, `VarType</api/language/vartype>` functions; `Var</api/language/var>`, `Static</api/language/static>` statements; `Encodings</api/text/encoding_text/encodings>` module; `TextEncoding</api/text/encoding_text/textencoding>`, `TextInputStream</api/files/textinputstream>` classes; `Boolean</api/data_types/boolean>`, `CFStringRef</api/data_types/additional_types/cfstringref>`, `Color</api/data_types/color>`, `CString</api/data_types/additional_types/cstring>`, `Currency</api/data_types/currency>`, `Double</api/data_types/double>`, `Integer</api/data_types/integer>`, `PString</api/data_types/additional_types/pstring>`, `Variant</api/data_types/variant>`, `WString</api/data_types/additional_types/wstring>` data types.

</div>
