String
class in package klyn

    public class String:

String

The String class is used to store and manipulate textual content. Since it is mutable, a string may change over the course of program execution.

Klyn strings are textual values encoded in UTF-8 and terminated by an ASCII zero byte (AZT model). They are designed for text, not for arbitrary binary payloads.

Practical consequences:

- Unicode text is supported through UTF-8.
- `size`, indexing and slicing operate on Unicode scalar values, not on

UTF-8 storage bytes.

- The code point `U+0000` (`Char(0)`) is reserved as the end-of-string

marker and cannot live inside a Klyn `String`.

- Binary data must be stored in byte arrays, streams or dedicated buffers,

not in `String`.

@example ```klyn text = "Klyn UTF-8 : café / π" print(text)

    @example ```klyn
    zero = String(Char(0))
    assert zero.size == 0

@since 1.0

Properties

Modifier and Type | Member | Description
--- | --- | ---
public readonly property | isEmpty `isEmpty as Boolean:` | Returns true if the string is empty.
public readonly native property | size `size as UInt` | Returns the number of characters in the string.

Constructors

Modifier and Type | Member | Description
--- | --- | ---
public | String `String():` | Builds the empty string.
public | String `String(value as Char):` | Builds a one-character string from a Char.
public | String `String(value as Char[]):` | Builds a string from a character array.
public | String `String(value as Object):` | Builds a string from any object by using its textual representation.

Methods

Modifier and Type | Member | Description
--- | --- | ---
public static | _slice `_slice(text as String, start as Int, stop as Int, sliceStep as Int, hasStart as Boolean, hasStop as Boolean) as String:` | Internal helper used by the compiler to implement slice syntax.
public native | capitalize `capitalize() as String` | Capitalizes the string in place (first character only).
public | center `center(width as Int, fill as Char = ' ') as String:` | Centers this string to the target width.
public native | contains `contains(value as String) as Boolean` | Returns true if this string contains the provided substring.
public | count `count(value as String) as UInt:` | Counts non-overlapping occurrences of a substring.
public | endsWith `endsWith(suffix as Object) as Boolean:` | Returns true if this string ends with the provided value.
public | endsWith `endsWith(suffixes as IList<String>) as Boolean:` | Returns true if this string ends with at least one suffix from the provided list.
public native | endsWith `endsWith(suffix as String) as Boolean` | Returns true if this string ends with the provided suffix.
public | equalsIgnoreCase `equalsIgnoreCase(other as String) as Boolean:` | Compares two strings without case sensitivity.
public native | indexOf `indexOf(value as String, start as Int = 0) as Int` | Finds the first index of a substring starting from a position.
public | isAlnum `isAlnum() as Boolean:` | Returns true if all characters are alphanumeric.
public | isAlpha `isAlpha() as Boolean:` | Returns true if all characters are alphabetic.
public | isBlank `isBlank() as Boolean:` | Returns true if the string is empty or only contains spaces.
public | isDigit `isDigit() as Boolean:` | Returns true if all characters are digits.
public | isLower `isLower() as Boolean:` | Returns true if all cased characters are lowercase and at least one cased character exists.
public | isSpace `isSpace() as Boolean:` | Returns true if all characters are whitespace.
public | isUpper `isUpper() as Boolean:` | Returns true if all cased characters are uppercase and at least one cased character exists.
public | join `join(values as Array<Char>) as String:` | Joins an array of characters using this string as separator.
public | join `join(values as Array<String>) as String:` | Joins an array of strings using this string as separator.
public | join `join(values as List<String>) as String:` | Joins a list of strings using this string as separator.
public native | lastIndexOf `lastIndexOf(value as String, start as Int = -1) as Int` | Finds the last index of a substring up to a position.
public | lower `lower() as String:` | Converts the string to lowercase in place.
public | lpad `lpad(width as Int, fill as Char = ' ') as String:` | Left pads this string to the target width.
public | ltrim `ltrim() as String:` | Removes leading whitespace in place.
public | matches `matches( regex as RegEx ) as Boolean:` | Tests the string against a regular expression.
public native | removeAccents `removeAccents() as String` | Removes accents in place.
public native | removeSGR `removeSGR(compatibility as String = "") as String` | Returns the string with ANSI SGR escape sequences removed.
public native | replace `replace(oldValue as String, newValue as String) as String` | Returns a copy where all occurrences of oldValue are replaced by newValue.
public native | replaceFirst `replaceFirst(oldValue as String, newValue as String) as String` | Returns a copy where the first occurrence of oldValue is replaced by newValue.
public native | replaceLast `replaceLast(oldValue as String, newValue as String) as String` | Returns a copy where the last occurrence of oldValue is replaced by newValue.
public | rpad `rpad(width as Int, fill as Char = ' ') as String:` | Right pads this string to the target width.
public | rtrim `rtrim() as String:` | Removes trailing whitespace in place.
public native | split `split(delimiter as String) as ArrayList<String>` | Splits the string using a string delimiter.
public native | startsWith `startsWith(prefix as String) as Boolean` | Returns true if this string starts with the provided prefix.
public | startsWith `startsWith(prefix as Object) as Boolean:` | Returns true if this string starts with the provided value.
public | startsWith `startsWith(prefixes as IList<String>) as Boolean:` | Returns true if this string starts with at least one prefix from the provided list.
public native | substring `substring(start as Int, length as Int = -1) as String throws IndexException` | Extracts a substring.
public | title `title() as String:` | Capitalizes each word in place.
public native | toCapitalize `toCapitalize() as String` | Returns a new string with the first character capitalized.
public | toLower `toLower() as String:` | Returns the string in lowercase.
public native | toRemoveAccents `toRemoveAccents() as String` | Returns a new string without accents.
public override | toString `toString() as String:` | Returns this string (identity conversion).
public | toTitle `toTitle() as String:` | Returns a title-cased copy of this string.
public | toTrim `toTrim() as String:` | Returns the string with leading and trailing whitespace removed.
public | toUpper `toUpper() as String:` | Returns the string in uppercase.
public | trim `trim() as String:` | Removes leading and trailing whitespace in place.
public | upper `upper() as String:` | Converts the string to uppercase in place.

Operators

Modifier and Type | Member | Description
--- | --- | ---
public native static | operator*( readonly first as String, readonly count as UInt ) as String | Repeats a string a given number of times.
public native | operator*=( readonly count as UInt ) as String | Repeats this string in place.
public native static | operator+( readonly first as String, readonly second as String ) as String | Concatenates two strings.
public native | operator+=( readonly second as String ) as String | Appends another string to this string (in place).
public native | operator[]( position as UInt ) as Char throws IndexException | Returns or sets the character at the given position.