Strings as series
Because strings are series of characters, all of the functions we talked about in this chapter also work for strings. Here are some examples of their usage with strings that show more advanced possibilities, which also apply to files, URLs, tags, and emails:
str: "Red";== "Red"
type? str ;== string!
string? str ;== true
series? str ;== true
Splitting a string – split
You can split a string on spaces, or on other characters, or even on strings - all these are called the delimiter, and the result of the split is a series. Here are some examples of this:
;-- see Chapter05/strings-as-series.red: s1: "The quick brown fox jumps over the lazy dog" split s1 " ";== ["The" "quick" "brown" "fox" "jumps" "over" "the" "lazy" "dog"] s2: "bracadabra" split s2 "a";== ["br" "c" "d" "br"] s3: "abracadabra" split s3 "a";== ["" "br" "c" "d" "br"]
From the last line, you can see that if the string starts with the delimiter, the first split item that will be found is an empty string ""
. The...