String

#import Builtin.String;

A builtin module defining the string type See Also: string

Functions


string(*char)

create :: string(c : exact *char)

Creates a string from a null-terminated character array

Arguments

c
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 : exact char)

Converts a char to a single-character string

string(uint8)

cast :: string(n : exact uint8)

Converts an uint8 to its decimal string representation

Arguments

n
exact uint8
The integer to convert

Returns:

A new string containing the decimal representation of n

string(double)

cast :: string(x : double)

Converts a double to its string representation using %g format

string(float)

cast :: string(x : float)

Converts a float to its string representation

print(string)

print :: (s : exact string)

A function to overload print(*char) for strings

printl(string)

printl :: (s : exact string)

A function to overload printl(*char) for strings

padRight(s, ch, targetLen)

padRight :: string(s : exact string, ch : exact char, targetLen : 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 : exact string, ch : exact char, targetLen : 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 : 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 : exact string, sub : 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.dump()

dump :: ()

Prints all of the info related to the string instance to the terminal

Operators


+(string, string)

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

Concatenates two strings together

Arguments

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

Returns:

A new string containing the concatenation of both strings

+(string, char)

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

Concatenates a string with a character

Arguments

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

Returns:

A new string containing the concatenation of the string and character

+(string, uint8)

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

Concatenates a string with a uint8

Arguments

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

Returns:

A new string containing the concatenation of the string and uint8

+(string, int64)

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

Concatenates a string with the decimal representation of an integer

Arguments

thisStr
exact string
The string
n
int64
The integer to append

Returns:

A new string containing the concatenation

+(int64, string)

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

Concatenates the decimal representation of an integer with a string

Arguments

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

Returns:

A new string containing the concatenation

+(string, float)

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

Concatenates a string with the decimal representation of a float

Arguments

thisStr
exact string
The string
f
float
The float to append

Returns:

A new string containing the concatenation

+(float, string)

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

Concatenates a decimal representation of a float with a string

Arguments

f
float
The float to append
thisStr
exact string
The string

Returns:

A new string containing the concatenation

+(*char, *char)

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

Concatenates two null-terminated character arrays

Arguments

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

Returns:

A pointer to a new character array containing the concatenation

==(*char, *char)

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

Compares two null-terminated character arrays for equality

Returns:

true if the contents are identical, false otherwise

==(string, string)

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

Compares two strings for equality by content

Returns:

true if both strings have equal length and identical characters