-
-
Notifications
You must be signed in to change notification settings - Fork 766
Allow concat 2 non-const strings? #2184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@xzores You're looking for import "core:strings"
// ...
s := strings.concatenate({a, b, c}) |
One way: a: strings.Builder
write_string(&a, "This is my string: ")
write_string(&a, My_other_non_const_string)
result := strings.to_string(a) Another way: buf := make([]u8, 500)
a := "This is my string: "
copy(buf, a)
copy(buf[len(a):], b)
result := string(buf[:len(a) + len(b)]) And there are other ways besides, like As for why not Odin is a low-level language, not Python. Programs are more maintainable and understandable when the code does what you write, not a whole bunch in addition implicitly. This explicitness (for sanity's sake) doesn't even inflate the line count compared to other low-level languages. A program ported to Odin from C often results in a third the number of lines. |
Thanks you guys! |
@xzores I highly recommmend joining the Odin discord for quick questions like this, lots of helpful folk around: https://discord.gg/U8Rd2suP Otherwise, there is also the Discussions page, which would be a better place for questions - https://github.com/odin-lang/Odin/discussions Issues are usually reserved for bug reports. |
Uh oh!
There was an error while loading. Please reload this page.
How can I concat 2 non-const strings?
Do I really have to make a string builder?
And if so would this really be the best way?
a : strings.Builder = builder_none();
write_string(&a, "This is my string: ");
write_string(&a, My_other_non_const_string);
And how would i get a string from this?
Would i do this:
clone_from_bytes(a.buf[:])?
Why not allow me just to do this:
"This is my string: " + My_other_non_const_string
The text was updated successfully, but these errors were encountered: