String
Definitions
def abbreviateLeft(w: Int32, s: String): String
SourceAbbreviate 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): String
SourceAbbreviate 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)
SourceFind 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)
SourceFind 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): String
SourceCenter 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): Char
SourceReturns the character at position i
in the string s
.
def codePointAt(i: Int32, s: String): Int32
SourceReturns the code point at position i
in the string s
.
def commonPrefix(s1: String, s2: String): String
SourceReturn 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): String
SourceReturn 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): String
SourceReturns the string s1
followed by the string s2
.
def contains(substr: { substr = String }, s: String): Bool
SourceReturns true
if and only if substr
is an infix of s
.
def countSubstring(substr: { substr = String }, s: String): Int32
SourceCount the occurrences of substr
in string s
.
def drop(n: Int32, s: String): String
SourceAlias for dropLeft
.
def dropLeft(n: Int32, s: String): String
SourceDrop 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): String
SourceDrop 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): String
SourceAlias for dropWhileLeft
.
def dropWhileAround(f: Char -> Bool, s: String): String
SourceReturns 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): String
SourceReturns 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): String
SourceReturns 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): Bool
SourceReturns true
if the string s
ends with the string suffix
.
def enumerator(rc: Region[r], s: String): Iterator[(Int32, Char), r, r] \ r
SourceReturns an iterator over l
zipped with the indices of the elements.
def exists(f: Char -> Bool \ ef, s: String): Bool \ ef
SourceReturns 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] \ ef
SourceOptionally 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]
SourceOptionally 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]
SourceReturns the positions of the all the elements in s
satisfying f
.
The function f
must be pure.
def flatten(xs: List[String]): String
SourceConcatenate a list of strings into a single string.
def foldLeft(f: b -> (Char -> b \ ef), x: b, s: String): b \ ef
SourceApplies 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 \ ef
SourceAccumulates 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 \ ef
SourceApplies f
to a start value x and all elements in
s` going from right to left.
def foldRight2(f: Char -> (Char -> (b -> b \ ef)), x: b, s: String, t: String): b \ ef
SourceAccumulates 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 \ ef
SourceReturns 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): String
SourceIndent 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]
SourceAlias for indexOfLeft
.
def indexOfLeft(substr: { substr = String }, s: String): Option[Int32]
SourceReturn 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]
SourceThis is indexOfLeft
with a start offset.
Returns None
if substr
is the empty string.
def indexOfRight(substr: { substr = String }, s: String): Option[Int32]
SourceReturn 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]
SourceThis is indexOfRight
with a start offset.
Returns None
if substr
is the empty string.
def indices(substr: { substr = String }, s: String): List[Int32]
SourceReturns 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 \ ef
SourceBuild a string of length len
by applying f
to the successive indices.
def intercalate(sep: String, xs: List[String]): String
SourceConcatenate a list of strings into a single string, inserting the separator sep
between
each pair of strings.
def intercalateChar(sep: Char, xs: List[String]): String
SourceConcatenate a list of strings into a single string, inserting the separator sep
between
each pair of strings.
def isAscii(s: String): Bool
SourceReturns true
if and only if all chars in s
are ascii characters.
Returns true
if s
is empty.
def isEmpty(s: String): Bool
SourceReturns true
if the string s
is the empty string.
def isMatch(regex: { regex = String }, s: String): Bool
SourceReturns 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): Bool
SourceReturns true
if the string s
is matched by the regular expression regex
at any point.
def isWhiteSpace(s: String): Bool
SourceReturns 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] \ r
SourceReturns an iterator over s
.
def length(s: String): Int32
SourceReturns the number of characters the string s
.
def levenshteinDistance(s: String, t: String): Int32
SourceCalculate 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(): String
SourceGet the system line separator.
def lines(s: String): List[String]
SourceSplit 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 \ ef
SourceReturns the result of applying f
to every character in s
.
def mapWithIndex(f: Int32 -> (Char -> Char \ ef), s: String): String \ ef
SourceReturns the result of applying f
to every character in s
along with that character's index.
def nonEmpty(s: String): Bool
SourceReturns true
if the string s
is non-empty.
def nth(i: Int32, s: String): Option[Char]
SourceOptionally return the character at position i
in the string s
.
def nthCodePoint(i: Int32, s: String): Option[Int32]
SourceOptionally returns the code point at position i
in the string s
.
def padLeft(w: Int32, c: Char, s: String): String
SourcePad the string s
at the left with the supplied char c
to fit the width w
.
def padRight(w: Int32, c: Char, s: String): String
SourcePad 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): String
SourceReturns 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): String
SourceReturns a string with the string s
repeated n
times.
Returns the empty string if n < 0
.
def replace(src: { src = String }, dst: { dst = String }, s: String): String
SourceReturns s
with every match of the substring src
replaced by the string dst
.
def replaceChar(src: { src = Char }, dst: { dst = Char }, s: String): String
SourceReturns s
with every match of the character src
replaced by the character dst
.
def replaceFirstMatch(regex: { regex = String }, to: { to = String }, s: String): String
SourceReturns 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): String
SourceReturns s
with every match of the regular expression regex
replaced by the string to
.
def reverse(s: String): String
SourceReturns the reverse of s
.
def rotateLeft(n: Int32, s: String): String
SourceRotate the contents of string s
by n
steps to the left.
def rotateRight(n: Int32, s: String): String
SourceRotate the contents of string s
by n
steps to the right.
def size(s: String): Int32
SourceReturns the number of characters the string s
.
def slice(start: { start = Int32 }, end: { end = Int32 }, s: String): String
SourceReturns 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): String
SourceGet the substring of s
to the left of index end
(exclusive).
sliceLeft == slice(0 , e, s)
def sliceRight(start: { start = Int32 }, s: String): String
SourceGet 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]
SourceSplits the string s
around matches of the regular expression regex
.
def splitAt(n: Int32, s: String): (String, String)
SourceSplit 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]
SourceSplit the string s
on matches of substr
.
def startsWith(prefix: { prefix = String }, s: String): Bool
SourceReturns true
if the string s
starts with the string prefix
.
def stripIndent(n: Int32, s: String): String
SourceStrip 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): String
SourceFor 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): String
SourceFor 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]
SourceReturns Some(suffix)
of string s
if its prefix matches substr
.
def stripSuffix(substr: { substr = String }, s: String): Option[String]
SourceReturns Some(prefix)
of string s
if its suffix matches substr
.
def take(n: Int32, s: String): String
SourceAlias for takeLeft
.
def takeLeft(n: Int32, s: String): String
SourceTake 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): String
SourceTake 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): String
SourceAlias for takeWileLeft
.
def takeWhileLeft(f: Char -> Bool, s: String): String
SourceReturns 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): String
SourceReturns 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] \ r
SourceReturns the given string s
as an array of characters.
def toChunks(k: Int32, s: String): List[String]
SourceSplit 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]
SourceReturns the given string s
as a list of characters.
def toLowerCase(s: String): String
SourceReturns the lower case version of the string s
.
def toRegex(regex: String): Result[String, Regex]
SourceCompile 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]
SourceCompile 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): String
SourceReturns the upper case version of the string s
.
def toVector(s: String): Vector[Char]
SourceReturns the given string s
as a vector of characters.
def trim(s: String): String
SourceReturns 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): String
SourceReturns string s
with all leading space characters removed.
def trimRight(s: String): String
SourceReturns string s
with all trailing space characters removed.
def unfold(f: b -> Option[(Char, b)] \ ef, x: b): String \ ef
SourceBuild 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 \ ef
SourceBuild 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 \ ef
SourceBuild 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 \ ef
SourceBuild 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]): String
SourceJoin 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]): String
SourceJoin the array of strings l
separating each pair of strings with a
single space character.
def unwrap(s: String): String
SourceUnwrap the string, replacing every newline with a space
def update(i: Int32, a: Char, s: String): String
SourceReturns 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]
SourceSplit 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): String
SourceWrap 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)]
SourceReturns 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 \ ef
SourceReturns 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.