Copy string

Purpose: Copies (sub)string to another string.

 copy-string <source string> to <dest string> \
     [ start-with <start with> ] \
     [ length <length> ]

Use copy-string to copy <source string> to <dest string>, in its entirety or just a part of it.

<start with> number (in "start-with" clause) is the position in <source string> to start copying from, with 0 being the first byte.

Without "length" clause, the whole of <source string> is copied. With "length" clause, exactly <length> bytes are copied into <dest string>.

You can copy a string to itself. In this case, the original string remains and the new string references a copy:
 set-string str = "original string" // string to change

 set-string orig = str // references original copy of the string to change

 copy-string str to str // make a copy of string to change and assign it to itself

 upper-string str // change the copy

 // Now "str" references "ORIGINAL STRING" 
 // and "orig" references "original string"

Substrings within expressions
You can use "@" to extract a substring and use it as a <string> in string-expressions; it takes the form of @(<source string>, <start with>, <length>), just like in copy-string. For instance:
 set-string str = "some string!"
 set-string res = @(str, 5,3) + " yes!"

The value of variable "res" would be "str yes!". The advantage of using @() notation in string expressions is that it is more efficient and of higher performance; a substring is added to other string(s) without being first copied into a separate string.
Examples
After copy-string below, "my_str" will be a copy of string "some value":
 set-string other_string="some value"
 copy-string other_string to my_str

Copy certain number of bytes, the result in "my_str" will be "ome":
 set-string other_string="some value"
 copy-string other_string to my_str length 3 start-with 1



Copyright (c) 2019-2025 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.