String

#import Builtin.String;

A builtin module defining the string type See Also: string

Functions


string(*char)

create :: string(c : const exact *char)

Creates a string from a null-terminated character array

Arguments

c
const exact *char
Pointer to a null-terminated character array

Returns:

A new string containing the characters from the array

string(int64)

cast :: string(n : int64)

Converts an integer to its decimal string representation

Arguments

n
int64
The integer to convert

Returns:

A new string containing the decimal representation of n

string(char)

cast :: string(c : const exact char)

Converts a char to a single-character string

string(uint8)

cast :: string(n : const exact uint8)

Converts an uint8 to its decimal string representation

Arguments

n
const exact uint8
The integer to convert

Returns:

A new string containing the decimal representation of n

string(double)

cast :: string(x : const double)

Converts a double to its string representation using %g format

string(float)

cast :: string(x : const float)

Converts a float to its string representation

print(string)

print :: (s : const exact string)

A function to overload print(*char) for strings

printl(string)

printl :: (s : const exact string)

A function to overload printl(*char) for strings

padRight(s, ch, targetLen)

padRight :: string(s : const exact string, ch : const exact char, targetLen : const int)

Returns s with ch appended on the right until length reaches targetLen. If s is already at or beyond targetLen, returns s unchanged.

padLeft(s, ch, targetLen)

padLeft :: string(s : const exact string, ch : const exact char, targetLen : const int)

Returns s with ch prepended on the left until length reaches targetLen. If s is already at or beyond targetLen, returns s unchanged.

basename(s)

basename :: string(s : const exact string)

Returns the filename portion of a path (everything after the last '/'). If no '/' is found, returns s unchanged.

find(s, sub)

find :: int64(s : const exact string, sub : const exact string)

Returns the index of the first occurrence of sub in s, or -1 if not found

Structs


string

@version(1):

The string data type You can declare a string using double quotes:

s : string = "Hello, World!";

Methods:

string.size()

size :: uint32()

Returns:

The length in characters of the string

string.substr(start, len)

substr :: string(start : int, len : int)

Returns a new string of len characters starting at start. Clamps start and len to valid bounds.

Arguments

start
int
Starting offset (clamped to [0, length))
len
int
Number of characters (clamped so start+len <= length)

Returns:

A new string

string.isEmpty()

isEmpty :: bool()

Returns:

true if the string has zero characters

string.contains(sub)

contains :: bool(sub : string)

Returns:

true if sub appears anywhere in this string

string.indexOf(sub)

indexOf :: int(sub : string)

Returns:

Index of the first occurrence of sub, or -1 if not found

string.startsWith(prefix)

startsWith :: bool(prefix : string)

Returns:

true if this string begins with prefix

string.endsWith(suffix)

endsWith :: bool(suffix : string)

Returns:

true if this string ends with suffix

string.repeat(n)

repeat :: string(n : int)

Returns:

This string concatenated with itself n times. Empty string if n <= 0.

Operators


+(string, string)

operator+ :: string(thisStr : const exact string, otherStr : const exact string)

Concatenates two strings together

Arguments

thisStr
const exact string
The first string
otherStr
const exact string
The second string

Returns:

A new string containing the concatenation of both strings

+(string, char)

operator+ :: string(thisStr : const exact string, ch : const exact char)

Concatenates a string with a character

Arguments

thisStr
const exact string
The string
ch
const exact char
The character to be added

Returns:

A new string containing the concatenation of the string and character

+(string, uint8)

operator+ :: string(thisStr : const exact string, n : const exact uint8)

Concatenates a string with a uint8

Arguments

thisStr
const exact string
The string
n
const exact uint8
The uint8 to be added

Returns:

A new string containing the concatenation of the string and uint8

+(string, int64)

operator+ :: string(thisStr : const exact string, n : const int64)

Concatenates a string with the decimal representation of an integer

Arguments

thisStr
const exact string
The string
n
const int64
The integer to append

Returns:

A new string containing the concatenation

+(int64, string)

operator+ :: string(n : const int64, otherStr : const exact string)

Concatenates the decimal representation of an integer with a string

Arguments

n
const int64
The integer to prepend
otherStr
const exact string
The string to append

Returns:

A new string containing the concatenation

+(string, float)

operator+ :: string(thisStr : const exact string, f : const float)

Concatenates a string with the decimal representation of a float

Arguments

thisStr
const exact string
The string
f
const float
The float to append

Returns:

A new string containing the concatenation

+(float, string)

operator+ :: string(f : const float, thisStr : const exact string)

Concatenates a decimal representation of a float with a string

Arguments

f
const float
The float to append
thisStr
const exact string
The string

Returns:

A new string containing the concatenation

+(*char, *char)

operator+ :: *char(thisStr : const exact *char, otherStr : const exact *char)

Concatenates two null-terminated character arrays

Arguments

thisStr
const exact *char
The first character array
otherStr
const exact *char
The second character array

Returns:

A pointer to a new character array containing the concatenation

==(*char, *char)

operator== :: bool(a : const exact *char, b : const exact *char)

Compares two null-terminated character arrays for equality

Returns:

true if the contents are identical, false otherwise

==(string, string)

operator== :: bool(a : const exact string, b : const exact string)

Compares two strings for equality by content

Returns:

true if both strings have equal length and identical characters