GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

πŸŽ€ GOLF(2gg) πŸŽ€

okay bestie, welcome to the GOLF(2gg) manual page, Development section, and today's main character is set-string πŸ’… buckle up.


🌸 NAME 🌸

set-string β€” (strings)

πŸ’– PURPOSE πŸ’–

Set the value of a string variable. that's it, that's the whole job, and it eats every time ✨

✨ SYNTAX ✨

set-string <variable> [ unquoted ] [ process-scope ] [ = <string> ]

set-string <variable> [ <index> ] = <number>

set-string <variable> length <length>

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the tea, bestie πŸ“ β€” your string variable <variable> gets assigned the value of <string> if the = clause is hanging out there. if it's not there? then <variable> just gets handed an empty string. simple as that, no cap.

If you bring the process-scope clause, then <variable> becomes a process scope variable β€” meaning its value persists from one request to another for the entire life of the process πŸ‘‘. but listen: this clause can only be used if <variable> didn't already exist. it's a first-come-first-served kind of situation, lowkey.

If you use the length clause, then the length of string <variable> gets set to <length>. and just like with literally every other string statement, you can only set the new length between zero and the current string length β€” that's the vibe check, no exceptions πŸ™ˆ. this is useful mostly when you're out here manipulating a string's individual bytes, and generally not in other cases (go peek at new-string for that).

If you use the unquoted clause, then the <string> literal is unquoted, and everything from the equal clause (=) to the rest of the line is the <string>. in that case you don't have to escape double quotes or backslashes at all, which is iconic honestly ✨. Note that in this case, unquoted and any other clause must appear prior to the equal clause (=) and after the variable, because otherwise they wouldn't be recognized. like, the parser simply will not see them, periodt. for instance:

set-string my_string unquoted = this is "some" string where there escape characters like \n do "not work"

This is the same as:

set-string my_string = "this is \"some\" string where there escape characters like \n do \"not work\""

The unquoted clause is your bestie when you're writing string literals that would otherwise need a ton of escaping πŸ’–. You can use a double backslash at the end of the line to split the line with a new line in between:

set-string unq1 unquoted =This is one line\        second line and\        third!

The above will create a string:

This is one line
second line and
third!

A string can also be represented as a concatenation of string literals β€” this is super useful when you want to preserve spaces, for instance 🌈:

set-string a="something is " \
    "  very good " \
    " with spaces!! "
// string is "something is   very good  with spaces!! "

You can also use set-string to set a byte inside it 🧚. in this case, the <index> byte in the <variable> string is set to <number>. <index> starts with 0 for the first byte. For instance, the resulting "str" will be "Aome string" since 65 is the number representation of 'A':

set-string str = "some string"
set-string str[0] = 65
// or using a character constant as a number, to the same effect
set-string str[0] = 'A'

πŸ¦„ EXAMPLES πŸ¦„

Initialize "my_string" variable to "":

set-string my_string

Initialize "my_string" variable to "abc":

set-string my_string = "abc"

πŸ”₯ SEE ALSO πŸ”₯

Strings

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 πŸ‘‘


and that's a wrap on GOLF(2gg), bestie 🫢 this page is version $VERSION, dated $DATE, and it absolutely served πŸ’…βœ¨

πŸ“¦ where this page comes from