std/string
March 17, 2026 ยท View on GitHub
Dynamic string type with automatic memory management.
Types
std::string
Dynamic string structure with automatic resizing.
Fields:
char* data- Character data pointerusize length- String lengthusize capacity- Allocated capacity
Constructors:
std::string this(char* str)
std::string this(usize n)
Methods
add
void add(char c)
Appends a character to the string.
append
void append(std::string str)
Appends another string.
appendC
void appendC(char* cstr, usize cstrlen)
void appendC(char* cstr)
void appendC(std::cstring cstr)
Appends C-string data.
indexOf
usize indexOf(char c)
usize indexOf(char* s)
usize indexOf(char* s, usize begin)
usize indexOf(std::string s)
Finds first occurrence of character or substring. Returns -1 if not found.
substring
std::string substring(usize from, usize to)
Extracts substring from index range.
split
std::vector<std::string> split(char ch)
Splits string by delimiter character.
replace
void replace(char c, char to)
std::string replace(char* from, char* to)
std::string replace(std::string from, std::string to)
Replaces characters or substrings.
insert
std::string insert(usize pos, char* str)
Inserts string at position.
trim
std::string trim()
std::string ltrim()
std::string rtrim()
Removes whitespace from both ends, left, or right.
copy
std::string copy()
Creates a copy of the string.
set
void set(usize index, char ch)
Sets character at index.
at
char at(usize index)
Gets character at index.
setValue
void setValue(char* a)
Replaces string content.
hash
uint hash()
Returns CRC32 hash of string.
Conversion Methods
char toChar()- First characterint toInt()- Parse as integerlong toLong()- Parse as longuint toUint()- Parse as unsigned intulong toUlong()- Parse as unsigned longcent toCent()- Parse as 128-bit intucent toUcent()- Parse as unsigned 128-bit intdouble toDouble()- Parse as doublechar* c()- Get C-string pointerbool isDeleted()- Check if string is deleted
Operators
std::string + std::string- Concatenationstd::string == std::string- Equality comparisonstd::string == char*- Equality with C-stringstd::string = char*- Assignment from C-string
Utility Functions
std::string::fromNumber
std::string fromNumber(cent n)
std::string fromNumber(long n)
std::string fromNumber(int n)
std::string fromNumber(short n)
std::string fromNumber(char n)
std::string fromNumber(bool n)
Converts signed numbers to strings.
std::string::fromUNumber
std::string fromUNumber(ucent n)
std::string fromUNumber(ulong n)
std::string fromUNumber(uint n)
std::string fromUNumber(ushort n)
std::string fromUNumber(uchar n)
Converts unsigned numbers to strings.
std::string::fromDouble
std::string fromDouble(double n)
std::string fromDoubleN(double n, int precision)
Converts double to string with optional precision.
std::string::fromFloat
std::string fromFloat(float n)
std::string fromFloatN(float n, int precision)
Converts float to string with optional precision.
std::sprint
std::string sprint(...)
Formats variadic arguments into a string.
std::gsprint
std::string gsprint(...)
Thread-safe global sprint using internal buffer.
Example
import <std/string>
std::string str = "Hello";
str.append(" World");
str.add('!');
std::string num = std::string::fromNumber(42);
int value = str.toInt();
std::vector<std::string> parts = str.split(' ');
std::string trimmed = str.trim();