# String
A collection of UTF-16 characters.
---
## Overview
Strings are a primitive datatype that contain a series of UTF-16 encoded characters.
To create a string use double quotes:
```misti
val greeting = "Hello there!"
// With type annotation
Str greeting = "Hello there!"
```
```md-warning
Misti doesn't allow string creation with single quotes ''
.
```
Strings can be concatenated with the plus `+` operator:
```misti
val name = "John"
val greeting = "Hello"
val fullGreeting = greeting + " " + name + "!"
// fullGreeting = "Hello John!"
```
In the future, the language will support string concatenation and multi-line strings.
## String comparison
To check if two strings are the same use the equal-to `==` operator.
```misti
"Hello" == "Hello" //: true
"Hello" == "hello" //: false
```
To check if two strings are different use the not-equal-to `!=` operator.
```misti
"abc" != "123" //: true
"xyz" != "xyz" //: false
```
Comparing strings with `<`, `<=`, `>` & `>=` will compare each character of the string,
based on the UTF-16 value.
```misti
"a" < "b" //: true
"a" < "A" //: false
"aab" > "aac" //: false
"aab" < "aac" //: true
```
## Automatic String conversion
Misti __does not__ automatically convert other datatypes to String.
```misti
val sentence = "My age is: " + 20 // This will throw an error
// ^
// Cannot concatenate a String and a Number.
```
To do so use the method `.toStr()` to explicitly convert to String.
```misti
val sentence = "My age is: " + 20.toStr() // ok
```
In the future, string interpolation will coerce datatypes into strings.
## Escape characters
Misti supports the following escape characters:
- `\"`
- `\\`
- `\n`
- `\r`
- `\t`
- `\b`
---
## API
Prelude's `Str` contains methods and functions created for their usage within Misti.
To access the underlying JavaScript methods, use the `js.String` module.
### Constructor
```misti
class String[T](T value)
where T -> Printable
```
Creates a string from `value`, by calling its `toStr` method.
#### Parameters
- `T value`: Any value that implements `Printable`, and therefore has a `toStr` method.
#### Examples
```misti
val age = String(20) //: "20"
val condition = String(false) //: "false"
val numbers = Array(1, 2, 3) |> String //: "1,2,3"
```
## Properties
### length
```misti
Num length
```
Returns the number of UTF-16 code units in the string.
#### Example
```misti
val name = "John"
name.length //: 4
```
---
## Methods
### charAt
```misti
fun charAt(Num position) -> Str?
```
Returns the UTF-16 code unit located at `position`.