GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

πŸ’… GOLF(2gg) β€” like, the manual page for new-string, bestie

okay so you found the 2gg manual (that's the manual name, she lives in the Development section, iykyk) and we're doing the new-string page. grab a boba, this one's short but it's lowkey iconic πŸ’–


✨ NAME ✨

new-string β€” it's in the strings family πŸŽ€ (the original just says (strings), and honestly? valid, that's the whole vibe)


πŸ¦‹ PURPOSE πŸ¦‹

Make a brand new string. that's it. that's the purpose. ✨


🌸 SYNTAX 🌸

new-string <variable> length <length>

πŸ’– DESCRIPTION πŸ’–

A new empty string called <variable> with length <length> gets allocated. bestie, listen: <variable> is an empty string (like, literally ""), BUT <length> bytes get allocated for it. so it's empty but also has room. it's giving "reserved seating" πŸ‘‘

new-string is your girl when you need to create a block of memory of a certain length and then go in and change its individual bytes (like with set-string, mwah 😘).

okay now the important tea: if <length> is a numeric literal, then <variable> gets allocated on the stack when <length> is less than 1024 bytes. which means those strings are faster at run time β€” especially for server processes, no cap. in all other cases, <variable> is dynamically allocated from the heap. fr fr.

also also also β€” <variable> (like all strings, text, binary, and however allocated, doesn't matter) has an implicit null byte placed after <length> bytes. sneaky little guy but he's always there 🫢


πŸ”₯ EXAMPLES πŸ”₯

Create a new string and then alter it, main character style:

new-string my_string length 30
set-string my_string[0] = 'A'
set-string my_string[1] = 'B'
set-string my_string[2] = 0
print-out my_string new-line

The output of above code would be "AB". slay πŸ’…


🌈 SEE ALSO 🌈

Strings β€” go read up, bestie

and the whole string clique, all of them, no one left out:

concatenate-strings copy-string count-substring delete-string lower-string new-string read-split replace-string set-string split-string string-length trim-string upper-string write-string

See all documentation for the rest of the lore πŸ’œ


k that's the page!! this was $VERSION, dated $DATE, and yes she's still filed under GOLF(2gg) πŸ’– bye bestie, go allocate something cute βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from