String

Definitions

def abbreviateLeft(w: Int32, s: String): StringSource

Abbreviate the string s if it exceeds the width w.

If the length of s exceeds w and w >= 3 then s is truncated and the first three characters are replaced with ellipses.

If the length of s exceeds w and w < 3 then the empty string is returned.

def abbreviateRight(w: Int32, s: String): StringSource

Abbreviate the string s if it exceeds the width w.

If the length of s exceeds w and w >= 3 then s is truncated and the last three characters are replaced with ellipses.

If the length of s exceeds w and w < 3 then the empty string is returned.

def breakOnLeft(substr: { substr = String }, s: String): (String, String)Source

Find the first instance of substr in string s, return a pair of the prefix of string s up to substr and the rest of string s including substr.

def breakOnRight(substr: { substr = String }, s: String): (String, String)Source

Find the last instance of substr in string s, return a pair of the initial string including substr and suffix from substr.

def center(w: Int32, c: Char, s: String): StringSource

Center the string s by padding with the supplied char c on both sides to fit the width w.

If the length of the string exceeds the given width, the string will be returned unchanged.

Requiring an uneven number of spaces, the string will be left biased, e.g String.center(4, '_', "a") -> "_a__".

def charAt(i: Int32, s: String): CharSource
def codePointAt(i: Int32, s: String): Int32Source

Returns the code point at position i in the string s.

def commonPrefix(s1: String, s2: String): StringSource

Return the common prefix of strings s1 and s2.

Returns the empty string if s1 and s2 do not share a common prefix.

def commonSuffix(s1: String, s2: String): StringSource

Return the common suffix of strings s1 and s2.

Returns the empty string if s1 and s2 do not share a common suffix.

def concat(s1: String, s2: String): StringSource

Returns the string s1 followed by the string s2.

def contains(substr: { substr = String }, s: String): BoolSource

Returns true if and only if substr is an infix of s.

def countSubstring(substr: { substr = String }, s: String): Int32Source

Count the occurrences of substr in string s.

def drop(n: Int32, s: String): StringSource

Alias for dropLeft.

def dropLeft(n: Int32, s: String): StringSource

Drop the first n characters of string s from the left.

If n extends past the end of string s, return the empty string.

def dropRight(n: Int32, s: String): StringSource

Drop the last n characters of string s from the right.

If n is greater than the length of string s, return the empty string.

def dropWhile(f: Char -> Bool, s: String): StringSource

Alias for dropWhileLeft.

def dropWhileAround(f: Char -> Bool, s: String): StringSource

Returns the middle of string s after dropping all the characters from both ends that satisfy the predicate f.

The function f must be pure.

def dropWhileLeft(f: Char -> Bool, s: String): StringSource

Returns the tail of string s after dropping all the initial chars that satisfy the predicate f.

The function f must be pure.

def dropWhileRight(f: Char -> Bool, s: String): StringSource

Returns the front of string s after dropping all the characters from the right end that satisfy the predicate f.

The function f must be pure.

def endsWith(suffix: { suffix = String }, s: String): BoolSource

Returns true if the string s ends with the string suffix.

def enumerator(rc: Region[r], s: String): Iterator[(Int32, Char), r, r] \ rSource

Returns an iterator over l zipped with the indices of the elements.

def exists(f: Char -> Bool \ ef, s: String): Bool \ efSource

Returns true if and only if at least one char in s satisfies the predicate f.

Returns false if a is empty.

def findIndexOfLeft(f: Char -> Bool \ ef, s: String): Option[Int32] \ efSource

Optionally returns the position of the first character in x satisfying f.

Returns None if no character in s satisfies f.

def findIndexOfRight(f: Char -> Bool, s: String): Option[Int32]Source

Optionally return the position of the first character in s satisfying f, reading right to left.

If nothing satisfies f return None.

def findIndices(f: Char -> Bool, s: String): List[Int32]Source

Returns the positions of the all the elements in s satisfying f.

The function f must be pure.

def flatten(xs: List[String]): StringSource

Concatenate a list of strings into a single string.

def foldLeft(f: b -> (Char -> b \ ef), x: b, s: String): b \ efSource

Applies f to a start value x and all elements in s going from left to right.

def foldLeft2(f: b -> (Char -> (Char -> b \ ef)), x: b, s: String, t: String): b \ efSource

Accumulates the result of applying f pairwise to the elements of s and t starting with the initial value x and going from left to right.

def foldRight(f: Char -> (b -> b \ ef), x: b, s: String): b \ efSource

Applies f to a start value x and all elements ins` going from right to left.

def foldRight2(f: Char -> (Char -> (b -> b \ ef)), x: b, s: String, t: String): b \ efSource

Accumulates the result of applying f pairwise to the elements of s and t starting with the initial value x and going from right to left.

def forAll(f: Char -> Bool \ ef, s: String): Bool \ efSource

Returns true if and only if all chars in s satisfy the predicate f.

Returns true if s is empty.

def indent(n: Int32, s: String): StringSource

Indent every line in string s by n spaces. n must be greater than 0.

If the string s in nonempty, the returned string normalizes line termination characters and adds a line terminator to the last line of the string if it does not already end with a newline.

If the string s is empty, then the empty string is returned.

def indexOf(substr: { substr = String }, s: String): Option[Int32]Source

Alias for indexOfLeft.

def indexOfLeft(substr: { substr = String }, s: String): Option[Int32]Source

Return the index of the first occurrence of substr in s from the left.

If substr is not present in s return None.

If substr is the empty string return None.

def indexOfLeftWithOffset(substr: { substr = String }, offset: { offset = Int32 }, s: String): Option[Int32]Source

This is indexOfLeft with a start offset.

Returns None if substr is the empty string.

def indexOfRight(substr: { substr = String }, s: String): Option[Int32]Source

Return the index of the first occurrence of substr in s from the right.

If substr is not present in s return None.

If substr is the empty string return None.

def indexOfRightWithOffset(substr: { substr = String }, offset: { offset = Int32 }, s: String): Option[Int32]Source

This is indexOfRight with a start offset.

Returns None if substr is the empty string.

def indices(substr: { substr = String }, s: String): List[Int32]Source

Returns the positions of the all the occurrences of substr in s.

Returns Nil if substr is the empty string.

def init(f: Int32 -> Char \ ef, len: Int32): String \ efSource

Build a string of length len by applying f to the successive indices.

def intercalate(sep: String, xs: List[String]): StringSource

Concatenate a list of strings into a single string, inserting the separator sep between each pair of strings.

def intercalateChar(sep: Char, xs: List[String]): StringSource

Concatenate a list of strings into a single string, inserting the separator sep between each pair of strings.

def isAscii(s: String): BoolSource

Returns true if and only if all chars in s are ascii characters.

Returns true if s is empty.

def isEmpty(s: String): BoolSource

Returns true if the string s is the empty string.

def isMatch(regex: { regex = String }, s: String): BoolSource

Returns true if the entire string s is matched by the regular expression regex.

Note - use isSubmatch to search for a substring.

def isSubmatch(regex: { regex = String }, s: String): BoolSource

Returns true if the string s is matched by the regular expression regex at any point.

def isWhiteSpace(s: String): BoolSource

Returns true if and only if all chars in s are white space characters.

Returns true if s is empty.

def iterator(rc: Region[r], s: String): Iterator[Char, r, r] \ rSource

Returns an iterator over s.

def length(s: String): Int32Source

Returns the length of the string s.

def levenshteinDistance(s: String, t: String): Int32Source

Calculate the Levenshtein distance between the strings s and t.

The answer is the number deletions, insertions or substitutions needed to turn string s into string t.

def lineSeparator(_unit: Unit): StringSource

Get the system line separator.

def lines(s: String): List[String]Source

Split the string s into an array of lines, breaking on newline.

Newline is recognized as any Unicode linebreak sequence including Windows (carriage return, line feed) or Unix (line feed).

def map(f: Char -> Char \ ef, s: String): String \ efSource

Returns the result of applying f to every character in s.

def mapWithIndex(f: Int32 -> (Char -> Char \ ef), s: String): String \ efSource

Returns the result of applying f to every character in s along with that character's index.

def nth(i: Int32, s: String): Option[Char]Source

Optionally return the character at position i in the string s.

def nthCodePoint(i: Int32, s: String): Option[Int32]Source

Optionally returns the code point at position i in the string s.

def padLeft(w: Int32, c: Char, s: String): StringSource

Pad the string s at the left with the supplied char c to fit the width w.

def padRight(w: Int32, c: Char, s: String): StringSource

Pad the string s at the right with the supplied char c to fit the width w.

def patch(i: Int32, n: Int32, sub: String, s: String): StringSource

Returns s with the n elements starting at index i replaced with the elements of sub.

If any of the indices i, i+1, i+2, ... , i+n-1 are out of range in s then no patching is done at these indices. If s becomes depleted then no further patching is done. If patching occurs at index i+j in s, then the element at index j in sub is used.

def repeat(n: Int32, s: String): StringSource

Returns a string with the string s repeated n times.

Returns the empty string if n < 0.

def replace(from: { from = String }, to: { to = String }, s: String): StringSource

Returns s with every match of the substring from replaced by the string to.

def replaceChar(from: { from = Char }, to: { to = Char }, s: String): StringSource

Returns s with every match of the character target replaced by the character rep.

def replaceFirstMatch(regex: { regex = String }, to: { to = String }, s: String): StringSource

Returns s with the first match of the regular expression regex replaced by the string to.

def replaceMatches(regex: { regex = String }, to: { to = String }, s: String): StringSource

Returns s with every match of the regular expression regex replaced by the string to.

def reverse(s: String): StringSource

Returns the reverse of s.

def rotateLeft(n: Int32, s: String): StringSource

Rotate the contents of string s by n steps to the left.

def rotateRight(n: Int32, s: String): StringSource

Rotate the contents of string s by n steps to the right.

def slice(start: { start = Int32 }, end: { end = Int32 }, s: String): StringSource

Returns the substring of s from index b (inclusive) to index e (exclusive).

If b or e are out-of-bounds, return the empty string.

def sliceLeft(end: { end = Int32 }, s: String): StringSource

Get the substring of s to the left of index end (exclusive).

sliceLeft == slice(0 , e, s)

def sliceRight(start: { start = Int32 }, s: String): StringSource

Get the substring of s to the right starting at index start (inclusive).

sliceRight == slice(start , length(s), s)

def split(regex: { regex = String }, s: String): List[String]Source

Splits the string s around matches of the regular expression regex.

def splitAt(n: Int32, s: String): (String, String)Source

Split the string s at the position n returning the left and right (inclusive n) parts.

If n exceeds the length of string s, return the whole string paired with the empty string. Symmetrically for n less than 0.

def splitOn(substr: { substr = String }, s: String): List[String]Source

Split the string s on matches of substr.

def startsWith(prefix: { prefix = String }, s: String): BoolSource

Returns true if the string s starts with the string prefix.

def stripIndent(n: Int32, s: String): StringSource

Strip every indented line in string s by n spaces. n must be greater than 0. Note, tabs are counted as a single space.

If the string s in nonempty, the returned string normalizes line termination characters and adds a line terminator to the last line of the string if it does not already end with a newline.

If the string s is empty, then the empty string is returned.

def stripMargin(s: String): StringSource

For every line in string s, strip a leading prefix consisting of blanks or control characters followed by | from the line, if such a prefix exists.

def stripMarginWith(margin: { margin = String }, s: String): StringSource

For every line in string s, strip a leading prefix consisting of blanks or control characters followed by margin from the line, if such a prefix exists.

def stripPrefix(substr: { substr = String }, s: String): Option[String]Source

Returns Some(suffix) of string s if its prefix matches substr.

def stripSuffix(substr: { substr = String }, s: String): Option[String]Source

Returns Some(prefix) of string s if its suffix matches substr.

def take(n: Int32, s: String): StringSource

Alias for takeLeft.

def takeLeft(n: Int32, s: String): StringSource

Take the first n characters of string s from the left.

If n extends past the end of string s, return all the characters of s.

def takeRight(n: Int32, s: String): StringSource

Take the last n characters of string s from the right.

If n is greater than the length of string s, return all the characters of s.

def takeWhile(f: Char -> Bool, s: String): StringSource

Alias for takeWileLeft.

def takeWhileLeft(f: Char -> Bool, s: String): StringSource

Returns the initial prefix of string s where all the chars satisfy the predicate f.

The function f must be pure.

def takeWhileRight(f: Char -> Bool, s: String): StringSource

Returns the suffix of string s where all the characters satisfy the predicate f.

The function f must be pure.

def toArray(rc: Region[r], s: String): Array[Char, r] \ rSource

Returns the given string s as an array of characters.

def toChunks(k: Int32, s: String): List[String]Source

Split the string s into chunks of length k, the last chunk may be smaller than k.

k should be greater than 0.

def toList(s: String): List[Char]Source

Returns the given string s as a list of characters.

def toLowerCase(s: String): StringSource

Returns the lower case version of the string s.

def toRegex(regex: String): Result[String, Regex]Source

Compile the regular expression regex into a Regex object (internally a Regex is java.util.regex.Pattern).

Returns Err if the regex is ill-formed and cannot be compiled.

The syntax of regular expressions is the same as Java, see the JDK Javadocs of the class util.regex.Pattern for reference.

Warning: It is strongly recommended to use a Regex literal instead of toRegex. Regex literals are checked at compile time.

def toRegexWithFlags(flags: Set[Flag], regex: String): Result[String, Regex]Source

Compile the regular expression regex into a Regex with the supplied flags.

Returns Err if the regex is ill-formed and cannot be compiled.

Warning: It is strongly recommended to use a Regex literal instead of toRegexWithFlags. Regex literals are checked at compile time. See the JDK documentation of java.util.regex.Pattern for guidance on enabling flags with embedded flag expressions.

def toUpperCase(s: String): StringSource

Returns the upper case version of the string s.

def toVector(s: String): Vector[Char]Source

Returns the given string s as a vector of characters.

def trim(s: String): StringSource

Returns a copy of the string s without trailing and leading whitespaces.

Returns a new empty string if there is no characters in s.

def trimLeft(s: String): StringSource

Returns string s with all leading space characters removed.

def trimRight(s: String): StringSource

Returns string s with all trailing space characters removed.

def unfold(f: b -> Option[(Char, b)] \ ef, x: b): String \ efSource

Build a string from the seed value x applying the function f until f returns None.

def unfoldString(f: b -> Option[(String, b)] \ ef, x: b): String \ efSource

Build a string from the seed value x applying the function f until f returns None.

This is a version of unfold where f generates substrings rather than chars.

def unfoldStringWithIter(f: Unit -> Option[String] \ ef): String \ efSource

Build a string by applying the function next to (). next is expected to encapsulate a stateful resource such as a file handle that can be iterated.

next should return Some(s) to signal a new substring s.

next should return None to signal the end of building the string.

def unfoldWithIter(f: Unit -> Option[Char] \ ef): String \ efSource

Build a string by applying the function next to (). next is expected to encapsulate a stateful resource such as a file handle that can be iterated.

next should return Some(c) to signal a new char c.

next should return None to signal the end of building the string.

def unlines(a: List[String]): StringSource

Join the list of strings a separating each pair of strings and ending the result string with the system dependent line separator.

def unwords(l: List[String]): StringSource

Join the array of strings l separating each pair of strings with a single space character.

def unwrap(s: String): StringSource

Unwrap the string, replacing every newline with a space

def update(i: Int32, a: Char, s: String): StringSource

Returns s with the element at index i replaced by a.

Returns s if i < 0 or i > length(xs)-1.

def words(s: String): List[String]Source

Split the string s into an list of words, dividing on one or more white space characters. Leading and trailing spaces are trimmed.

def wrap(w: Int32, s: String): StringSource

Wrap the string s into lines that are each at most as long as w, breaking on whitespace.

If a line contains a single word that exceeds the length of w, the word will be broken.

def zip(a: String, b: String): List[(Char, Char)]Source

Returns an array where the element at index i is (x, y) where x is the element at index i in a and y is the element at index i in b.

If either a or b becomes depleted, then no further elements are added to the resulting array.

def zipWith(f: Char -> (Char -> Char \ ef), a: String, b: String): String \ efSource

Returns a string where the element at index i is f(x, y) where x is the element at index i in a and y is the element at index i in b.

If either a or b becomes depleted, then no further elements are added to the resulting array.