std.string

Module entries: atoi(), cToString(), cToStringFree(), endsWith(), find(), itoa(), join(), replace(), slice(), split(), startsWith(), strip(), toHexString(), toStringz()

atoi(s)

int atoi(string s)

The string s converted to an integer.

Example:

assert(atoi("5") == 5);
assert(atoi("-3") == -3);
cToString(ptr)

string cToString(char* ptr)

Convert a C zero-terminated string pointer to a Neat string.

cToStringFree(ptr)

string cToStringFree(char* ptr)

Convert a C zero-terminated string pointer to a Neat string.

For convenience, also frees the original pointer.

endsWith(haystack, needle)

bool endsWith(string haystack, string needle)

Returns true if haystack ends with needle.

Example:

assert("Hello World".endsWith("World"));
assert(!"Hello World".endsWith("Hello"));
find(text, match)

int find(string text, string match)

The offset in text at which match occurs, or -1 if it doesn’t.

Example:

assert("Hello World".find("o") == 4);
assert("Hello World".find("p") == -1);
itoa(i)

string itoa(int i)

The integer i converted to a string.

Example:

assert(itoa(5) == "5");
assert(itoa(-3) == "-3");
join(array, sep)

string join(string[] array, string sep)

All strings in array, concatenated and joined with sep.

replace(str, match, replace)

string replace(string str, string match, string replace)

str with all occurrences of match replaced with replace.

slice(text, sep)

(string fragment, string rest) slice(string text, string sep)

text split into two halves at the first occurrence of sep.

split(text, sep)

string[] split(string text, string sep)

text split at every occurrence of sep.

Example:

assert("Hello World".split(" ") == ["Hello", "World"]);
assert("Hello".split(" ") == ["Hello"]);
assert("".split(" ").length == 0);
startsWith(haystack, needle)

bool startsWith(string haystack, string needle)

Returns true if haystack starts with needle.

Example:

assert("Hello World".startsWith("Hello"));
assert(!"Hello World".startsWith("World"));
strip(text)

string strip(string text)

text, with leading and trailing whitespace removed.

toHexString(data)

string toHexString(ubyte[] data)

The lower-case hexadecimal representation of the given byte data data.

toStringz(s)

char* toStringz(string s)

Convert a Neat string to a C zero-terminated string pointer.