GOLF(2gg)

NAME
set-string - (strings)

PURPOSE
Set value of a string variable.

SYNTAX

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

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

        set-string <variable> length <length>

DESCRIPTION
String variable <variable> will be assigned a value of <string> if clause "=" is present; otherwise <variable> is assigned an empty string.

If "process-scope" clause is used, then <variable> will be of process scope, meaning its value will persist from one request to another for the life of the process; this clause can only be used if <variable> did not already exist.

If "length" clause is used, then the length of string <variable> is set to <length>. Just like with all other string statements, you can only set the new length of the string between zero and the current string length. This is useful mostly when manipulating string's individual bytes, and generally not in other cases (see new-string).

If "unquoted" clause is used, then <string> literal is unquoted, and everything from equal clause ("=") to the rest of the line is a <string>; in this case there is no need to escape double quotes or backslashes. Note that in this case, "unquoted" and any other clause must appear prior to equal clause ("=") and after variable, because they wouldn't otherwise be recognized. 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\""

"unquoted" clause is useful when writing string literals that would otherwise need lots of escaping. You can use double backslash at the end of the line to split the line with 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 be represented as a concatenation of string literals; this is 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 in it; in this case <index> byte in <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 a 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