Strings

A string in StackLang represents a sequence of text characters. What character set is supported is, however, implementation specific. Currently, only ASCII characters are guarenteed to be supported. A string is formed by entering an escaped string between a set of double quotes. This is then parsed into an unescaped string, but is still displayed as an escaped string.

An EBNF definition of a valid input string is given below.

                                    quote-symbol = '"' ;
                                    backslash-symbol = "\" ;
                                    newline-character-symbol = "n" ;
                                    character-not-special = ? Any ASCII character except for one of: \" ? ;
                                    
                                    escape-sequence = backslash-symbol, (quote-symbol | backslash-symbol | newline-character-symbol) ;
                                    character-sequence = character-not-special | escape-sequence
                                    
string = quote-symbol, {character - sequence}, quote-symbol

String-related Commands

Type Predicates

string? : Any -> Boolean
Produces true if elemnt is a string.

empty-string? : Any -> Boolean
Produces true if elemnt is an empty string - any string with length zero.

non-empty-string? : Any -> Boolean
Produces true if elemnt is an non-empty string - any string with length more than zero.

String Operations

string-length : String -> Number
Produces the length of the string.

string-ref : Number String -> String
Produces the n'th character as a one character long string. Fails with a RuntimeError if the number is not valid.

string-insert : String Number String
Inserts the first string into the second, such that the first character of the first string is a position n in the second string.

substring : Number Number String -> String
Produces a substring. The first number is the starting index (included), and the second number is the ending index (not included). Fails with a RuntimeError if any of the numbers are invalid for this string.

string-append : String String -> String
Appends the first string to the end of the second string.

toupper : String -> String
Converts the string to all uppercase characters.

tolower : String -> String
Converts the string to all lowercase characters.

join : String Substack(String) -> String
Appends all of the strings from the substack in order (active end first), inserting the first string in between every one of them.

split : String String -> Substack(String)
Takes the second string, and splits it into a separate string whenever the first string is encountered. Inverse of string-join. If the first string is an empty string, splits the second string on every character.

replace : String String String -> String
Takes the third string, and replaces all occurrences of the first string with the second string.

trim : String -> String
Removes all whitespace (spaces, newlines, tabs) from the front and the end of the string.

build-string : Number String -> String
Creates a string by string-append-ing together n copies of the given string.

Comparisons

string-equal? : String String -> Boolean
Produces true if the two strings have the same characters in the same order.

string-not-equal? : String String -> Boolean
Produces true if the two strings are not equal.

string-alphabetic? : String String -> Boolean
Produces true if the first string is alphabetically later than the second string.

string-alphabetic-equal? : String String -> Boolean
Produces true if the first string is alphabetically later than or equal to the second string.

string-reverse-alphabetic? : String String -> Boolean
Produces true if the first string is alphabetically sooner than the second string.

string-reverse-alphabetic-equal? : String String -> Boolean
Produces true if the first string is alphabetically sooner than or equal to the second string.

string-equal-ci? : String String -> Boolean
Like string-equal?, but ignores case.

string-equal-ci? : String String -> Boolean
Like string-not-equal?, but ignores case.

string-alphabetic-ci? : String String -> Boolean
Like string-alphabetic?, but ignores case.

string-alphabetic-equal-ci? : String String -> Boolean
Like string-alphabetic-equal?, but ignores case.

string-reverse-alphabetic-ci? : String String -> Boolean
Like string-reverse-alphabetic?, but ignores case.

string-reverse-alphabetic-equal-ci? : String String -> Boolean
Like string-reverse-alphabetic-equal?, but ignores case.

string-contains? : String String -> Boolean
Produces true if the second string contains the first string.

string-prefix? : String String -> Boolean
Produces true if the second string starts with the first string.

string-suffix? : String String -> Boolean
Produces true if the second string ends with the first string.