String
An array of chars (UTF-16 code units).
A data type used mainly to represent text, denoted by the '
or "
its wrapped within.
You can indicate that a String is raw and should treat \
as a literal character by prefixing it with r
. Strings in birb are multiline by default:
You can use the +
operator to concat Strings:
Properties
codeUnits
List codeUnits
Returns a list containing the 16-bit Unicode code units of this String.
Example
isEmpty
bool isEmpty
True if this String is empty.
Example
isNotEmpty
bool isNotEmpty
True if this String is not empty.
Example
length
int length
Returns an int containing the length of this String.
Example
mock
String mock
Prints this String before reading a line from StdIn.
Example
toBinary
List toBinary
Returns a list with the strings code units represented as binary.
Example
toHex
List toHex
Returns a list with the strings code units represented as hexadecimal.
Example
toOct
List toOct
Returns a list with the strings code units represented as octal.
Example
runtimeType
String runtimeType
Returns a list with the strings code units represented as octal.
Example
Methods
codeUnitAt
int codeUnitAt(int index)
Returns the codeUnit at the given index.
Example
compareTo
int compareTo(String str)
Compares the codeUnits of this String to str
. The returned in is negative if this String is ordered before str
, positive if after and zero if they are the same.
Example
contains
bool contains(String other, int startIndex)
Returns true if this String contains other
at or after the startIndex.
Example
endsWith
bool endsWith(String str)
Returns true if this String ends with str
.
Example
indexOf
int indexOf(String str, int start)
Returns the index of the first match of str
starting from start
within this String
.
Example
lastIndexOf
int lastIndexOf(String str, int start)
Returns the index of the last match of str
starting from start
within this String
.
Example
padLeft
String padLeft(int width, String padding)
Adds padding
to the left of this String while it is smaller than width
and returns a new String.
Example
padRight
String padRight(int width, String padding)
Adds padding
to the right of this String while it is smaller than width
and returns a new String.
Example
replaceAll
String replaceAll(String from, String replace)
Replaces all occurrences of from
with replace
.
Example
replaceFirst
String replaceFirst(String from, String replace)
Replaces the first occurrences of from
with replace
.
Example
replaceRange
String replaceRange(int start, int end, String replace)
Replaces a substring between start
and end
with replace
.
Example
split
List split(String str)
Splits the String at all occurrences of str
.
Example
startsWith
bool startsWith(String str)
Returns true if this String starts with str
.
Example
substring
String substring(int start, int end)
Returns a substring of this String between start
and end
.
Example
toLowerCase
String toLowerCase()
Returns this String as lower case.
Example
toUpperCase
String toUpperCase()
Returns this String as upper case.
Example
trim
String trim()
Returns this String without any leading or trailing whitespace.
Example
trimLeft
String trimLeft()
Returns this String without any leading whitespace.
Example
trimRight
String trimRight()
Returns this String without any trailing whitespace.
Example
Operators
Operator | Description |
---|---|
+ | Concatenates two Strings returning a single String |
* | Multiplies the String by the right value, ie: "1" * 3 // => "111" |