Learn Aero / Strings
Strings
Aero's str is a NUL-terminated C string (managed by malloc). It's the most frictionless representation for C interop.
Basic Operations
let s = "hello";
print(len(s)); // 5
print(s + " world"); // "hello world"(字面量拼接零成本)
print(s[0]); // 104('h' 的数值)len(s) | byte length |
s1 + s2 | concatenation (zero cost for literals; variables require runtime allocation) |
== != < > <= >= | lexicographic comparison |
s[i] | numeric value of the i-th byte |
int_to_str(n) | integer → string (needs str_free) |
str_to_int(s) | string → integer (returns 0 on failure) |
substr(s, start, end) | slice [start, end) (needs str_free) |
str_contains(hay, needle) | whether it contains |
str_find(hay, needle) | position of first occurrence, -1 if not found |
str_cmp(a, b) | C-style comparison: negative / 0 / positive |
str_free(s) | frees a runtime-allocated string |
Runtime Allocations Must Be Freed
Any string allocated at runtime (
int_to_str, substr, variable concatenation) needs str_free after use, otherwise it leaks.let s = int_to_str(12345);
print(s); // 12345
str_free(s); // 释放File I/O
let text = read_file("data.txt"); // 读整个文件,失败返回空串
write_file("out.txt", text); // 写文件,返回字节数,失败 -1