7 ms·
If there is no string concatenation operator (for run time), how do you concatenate strings at run time with Zig? Depends on what you work on, I guess, but in
by IlliOnato 3y ago
If there is no string concatenation operator (for run time), how do you concatenate strings at run time with Zig?
Depends on what you work on, I guess, but in my area of expertise string operations like concatenation are bread-and-butter.
- WalterBright 3y agoEasy string (and array) concatenation is a godsend: string b = "betty"; string s = "hello " ~ b;
- Leherenn 3y agoYou allocate a big enough buffer, and copy the strings in the buffer, same as in C.
- anonymoushn 3y agoYou probably use fmt instead. You provide a format string, an anonymous struct (a tuple) containing the values to be formatted, and a writer or byte slice, and you get the formatted string written to the writer or the byte slice.