String
classin packageklyn
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. - 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 Builds the empty string.
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 native capitalize
capitalize() as String
Capitalizes the string in place (first character only).
public center
center(width as UInt, fill as Char = ' ') as String:
Centers this string in place 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 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 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 List<String>) as String:
Joins a list of strings using this string as separator.
public 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 UInt, fill as Char = ' ') as String:
Left pads this string in place 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 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 replace
replace(oldValue as String, newValue as String) as String:
Replaces all occurrences of oldValue by newValue in place.
public replaceFirst
replaceFirst(oldValue as String, newValue as String) as String:
Replaces the first occurrence of oldValue by newValue in place.
public replaceLast
replaceLast(oldValue as String, newValue as String) as String:
Replaces the last occurrence of oldValue by newValue in place.
public rpad
rpad(width as UInt, fill as Char = ' ') as String:
Right pads this string in place to the target width.
public rtrim
rtrim() as String:
Removes trailing whitespace in place.
public 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 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 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.