St

Strings in Factor

42 exercises

About Strings

A string in Factor is a sequence of characters and shares the full sequences protocol — length, nth, head, tail, map, filter, and so on — alongside its dedicated vocabularies.

"hello"  length .       ! => 5
"hello"  reverse .      ! => "olleh"
"abcdef" 3 head .       ! => "abc"

The string-specific words live mostly in splitting, ascii, and unicode:

word vocab what it does
split1 splitting cut on the first occurrence
split splitting cut on any character in a set
harvest sequences drop empty pieces from a split result
replace splitting substitute a substring
surround sequences wrap with a prefix and suffix
glue sequences join two strings with a separator
join sequences join an array of strings with a separator
>lower ascii lowercase (ASCII)
>upper ascii uppercase (ASCII)
[ blank? ] trim sequences strip leading/trailing whitespace
first, second, third, fourth sequences the leading slot
first2, first3 sequences unpack two or three leading slots
>string strings turn a sequence of chars into a string
1string strings wrap a single character into a one-character string
CHAR: x parser a single-character literal (e.g. CHAR: A → 65)

For numeric ↔ string round-tripping, math.parser provides number>string and string>number. For format-string output, formatting provides sprintf and friends.

For Unicode-aware case conversion or character classification, use the corresponding words in unicode.

Edit via GitHub The link opens in a new window or tab

Learn Strings

Practicing is locked

Unlock 6 more exercises to practice Strings