Skip to content

String

Represents a string value. Strings can be prefixed with r to parse them as they are. Strings are always multi-line.

Syntax (RegExp)
'[\S\s]*'
"[\S\s]*"
r'[\S\s]*'
r"[\S\s]*"
Example
'Hello'
"Hello"
r'This is a raw string'
r"This is a raw string"
'Supports escape sequences like \t \n'
"but also unicodes like \u0041 and \x41"

'Easy
and
peasy'

Properties

isEmpty

Is string empty?

Signature
() => Boolean

isNotEmpty

Is string not empty?

Signature
() => Boolean

length

Length of the string.

Signature
() => Number

compareTo

Compare to another string. Returns 0 if equal.

Signature
(other: String) => Number

contains

Check if other is present in the string.

Signature
(other: String) => Boolean

startsWith

Check if the string is prefixed with other.

Signature
(other: String) => Boolean

endsWith

Check if the string is suffixed with other.

Signature
(other: String) => Boolean

indexOf

Position of substring in the string. Returns -1 if not present.

Signature
(substring: String) => Number

substring

Returns a substring between start and end.

Signature
(start: Number, end: Number) => String

replaceFirst

Replaces first substring with with.

Signature
(pattern: String, with: String) => String

replaceAll

Replaces all substring with with.

Signature
(pattern: String, with: String) => String

replaceFirstMapped

Replaces first substring with value returned by with.

Signature
(pattern: String, mapper: (String) => String) => String

replaceAllMapped

Replaces all substring with value returned by with.

Signature
(pattern: String, mapper: (String) => String) => String

trim

Removes all whitespaces at the ends.

Signature
() => String

trimLeft

Removes all whitespaces at the start.

Signature
() => String

trimRight

Removes all whitespaces at the end.

Signature
() => String

padLeft

Pads using with at the start.

Signature
(length: Number, with: String) => String

padRight

Pads using with at the end.

Signature
(length: Number, with: String) => String

split

Splits the string at splitters.

Signature
(splitter: String) => List<String>

codeUnitAt

Returns code-unit at index.

Signature
(index: Number) => String

toCodeUnits

Returns code-units of the string.

Signature
() => List<Number>

toLowerCase

Returns the string in lowercase.

Signature
() => String

toUpperCase

Returns the string in uppercase.

Signature
() => String

format

Returns the formatted string. Example: "{} {1}".format(["Hello", "World"]), "{hello} {world}".format({ hello: "Hello", world: "World" }) returns Hello World

Signature
(env: Object | List<Any>) => String