String length

Purpose: Get string length.

string-length <string> to <length>

string-length will place the number of bytes in <string> into number <length>.

Note that <string> does not need to be null-terminated, meaning it can be a binary or text string. <length> is the number of bytes comprising any such string.

Note that length of the string is not calculated; rather it is kept in a pre-fetched, cached location right next to the data itself for fast retrieval.
String length as a function
You can also use "strlen()" function to obtain string length as a number. You can use it in number or double expressions. The following two are equivalent:
set-string s = "string"
string-length s to len
print-out "Half of length is ", len/2 new-line

and
set-string s = "string"
print-out "Half of length is ", strlen(s)/2 new-line

which would yield "3".

An example in expression:
set-string s = "other string"
set-number n = strlen("some string") + strlen (s) -1

The result for "n" would be 22.
Examples
Variable "len" will be 6:
set-string str = "string"
string-length str to len

Variable "len2" will be 18 - the string has a null character in the middle of it:
set-string str2 = "string" "\x00 after null"
string-length str2 to len2

See also
Strings
copy-string  
count-substring  
delete-string  
double-string  
lower-string  
match-regex  
new-string  
number-string  
read-split  
replace-string  
scan-string  
set-string  
split-string  
string-double  
string-expressions  
string-length  
string-number  
trim-string  
upper-string  
write-string  
See all
documentation


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