Returns a String.Slice obtained by removing the specified number of characters (Unicode code
points) from the start of the string.
If n is greater than s.length, returns an empty slice.
This is a cheap operation because it does not allocate a new string to hold the result.
To convert the result into a string, use String.Slice.copy.
Examples:
"red green blue".drop 4 == "green blue".toSlice"red green blue".drop 10 == "blue".toSlice"red green blue".drop 50 == "".toSlice"مرحبا بالعالم".drop 3 == "با بالعالم".toSlice
Instances For
Returns a String.Slice obtained by removing the specified number of characters (Unicode code
points) from the end of the string.
If n is greater than s.length, returns an empty slice.
This is a cheap operation because it does not allocate a new string to hold the result.
To convert the result into a string, use String.Slice.copy.
Examples:
"red green blue".dropEnd 5 == "red green".toSlice"red green blue".dropEnd 11 == "red".toSlice"red green blue".dropEnd 50 == "".toSlice"مرحبا بالعالم".dropEnd 3 == "مرحبا بالع".toSlice
Instances For
Equations
- String.Internal.dropRightImpl s n = (s.dropEnd n).copy
Instances For
Returns a String.Slice that contains the first n characters (Unicode code points) of
s.
If n is greater than s.length, returns s.toSlice.
This is a cheap operation because it does not allocate a new string to hold the result.
To convert the result into a string, use String.Slice.copy.
Examples:
"red green blue".take 3 == "red".toSlice"red green blue".take 1 == "r".toSlice"red green blue".take 0 == "".toSlice"red green blue".take 100 == "red green blue".toSlice"مرحبا بالعالم".take 5 == "مرحبا".toSlice
Instances For
Returns a String.Slice that contains the last n characters (Unicode code points) of
s.
If n is greater than s.length, returns s.toSlice.
This is a cheap operation because it does not allocate a new string to hold the result.
To convert the result into a string, use String.Slice.copy.
Examples:
"red green blue".takeEnd 4 == "blue".toSlice"red green blue".takeEnd 1 == "e".toSlice"red green blue".takeEnd 0 == "".toSlice"red green blue".takeEnd 100 == "red green blue".toSlice"مرحبا بالعالم".takeEnd 5 == "لعالم".toSlice
Instances For
Creates a string slice that contains the longest prefix of s in which pat matched
(potentially repeatedly).
This is a cheap operation because it does not allocate a new string to hold the result.
To convert the result into a string, use String.Slice.copy.
This function is generic over all currently supported patterns.
Examples:
"red green blue".takeWhile Char.isLower == "red".toSlice"red green blue".takeWhile 'r' == "r".toSlice"red red green blue".takeWhile "red " == "red red ".toSlice"red green blue".takeWhile (fun (_ : Char) => true) == "red green blue".toSlice
Instances For
Creates a string slice by removing the longest prefix from s in which pat matched
(potentially repeatedly).
This is a cheap operation because it does not allocate a new string to hold the result.
To convert the result into a string, use String.Slice.copy.
This function is generic over all currently supported patterns.
Examples:
"red green blue".dropWhile Char.isLower == " green blue".toSlice"red green blue".dropWhile 'r' == "ed green blue".toSlice"red red green blue".dropWhile "red " == "green blue".toSlice"red green blue".dropWhile (fun (_ : Char) => true) == "".toSlice
Instances For
Creates a string slice that contains the longest suffix of s in which pat matched
(potentially repeatedly).
This is a cheap operation because it does not allocate a new string to hold the result.
To convert the result into a string, use String.Slice.copy.
This function is generic over all currently supported patterns.
Examples:
"red green blue".takeEndWhile Char.isLower == "blue".toSlice"red green blue".takeEndWhile 'e' == "e".toSlice"red green blue".takeEndWhile (fun (_ : Char) => true) == "red green blue".toSlice
Equations
- s.takeEndWhile pat = s.toSlice.takeEndWhile pat
Instances For
Equations
- s.takeRightWhile p = (s.takeEndWhile p).toString
Instances For
Equations
- s.takeRightWhile p = s.takeEndWhile p
Instances For
Creates a new string by removing the longest suffix from s in which pat matches
(potentially repeatedly).
This is a cheap operation because it does not allocate a new string to hold the result.
To convert the result into a string, use String.Slice.copy.
This function is generic over all currently supported patterns.
Examples:
"red green blue".dropEndWhile Char.isLower == "red green ".toSlice"red green blue".dropEndWhile 'e' == "red green blu".toSlice"red green blue".dropEndWhile (fun (_ : Char) => true) == "".toSlice
Equations
- s.dropEndWhile pat = s.toSlice.dropEndWhile pat
Instances For
Equations
- s.dropRightWhile p = (s.dropEndWhile p).toString
Instances For
Equations
- s.dropRightWhile p = s.dropEndWhile p
Instances For
Checks whether the first string (s) begins with the pattern (pat).
String.isPrefixOf is a version that takes the
potential prefix before the string.
Examples:
"red green blue".startsWith "red" = true"red green blue".startsWith "green" = false"red green blue".startsWith "" = true"red green blue".startsWith 'r' = true"red green blue".startsWith Char.isLower = true
Equations
- s.startsWith pat = s.toSlice.startsWith pat
Instances For
Checks whether the second string (s) begins with a prefix (p).
This function is generic over all currently supported patterns.
String.startsWith is a version that takes the potential prefix after the string.
Examples:
"red".isPrefixOf "red green blue" = true"green".isPrefixOf "red green blue" = false"".isPrefixOf "red green blue" = true
Equations
- p.isPrefixOf s = s.startsWith p
Instances For
Equations
Instances For
Checks whether the string (s) ends with the pattern (pat).
This function is generic over all currently supported patterns.
Examples:
"red green blue".endsWith "blue" = true"red green blue".endsWith "green" = false"red green blue".endsWith "" = true"red green blue".endsWith 'e' = true"red green blue".endsWith Char.isLower = true
Instances For
Removes trailing whitespace from a string by returning a slice whose end position is the last non-whitespace character, or the start position if there is no non-whitespace character.
“Whitespace” is defined as characters for which Char.isWhitespace returns true.
Examples:
"abc".trimAsciiEnd == "abc".toSlice" abc".trimAsciiEnd == " abc".toSlice"abc \t ".trimAsciiEnd == "abc".toSlice" abc ".trimAsciiEnd == " abc".toSlice"abc\ndef\n".trimAsciiEnd == "abc\ndef".toSlice
Equations
Instances For
Equations
- s.trimRight = s.trimAsciiEnd.copy
Instances For
Equations
- s.trimRight = s.trimAsciiEnd
Instances For
Removes leading whitespace from a string by returning a slice whose start position is the first non-whitespace character, or the end position if there is no non-whitespace character.
“Whitespace” is defined as characters for which Char.isWhitespace returns true.
Examples:
"abc".trimAsciiStart == "abc".toSlice" abc".trimAsciiStart == "abc".toSlice"abc \t ".trimAsciiStart == "abc \t ".toSlice" abc ".trimAsciiStart == "abc ".toSlice"abc\ndef\n".trimAsciiStart == "abc\ndef\n".toSlice
Equations
Instances For
Equations
- s.trimLeft = s.trimAsciiStart.copy
Instances For
Equations
- s.trimLeft = s.trimAsciiStart
Instances For
Removes leading and trailing whitespace from a string.
“Whitespace” is defined as characters for which Char.isWhitespace returns true.
Examples:
"abc".trimAscii == "abc".toSlice" abc".trimAscii == "abc".toSlice"abc \t ".trimAscii == "abc".toSlice" abc ".trimAscii == "abc".toSlice"abc\ndef\n".trimAscii == "abc\ndef".toSlice
Instances For
Equations
Instances For
Repeatedly increments a position in a string, as if by String.Pos.Raw.next, while the
predicate p returns true for the character at the position. Stops incrementing at
the end of the string or when p returns false for the current character.
Examples:
let s := " a "; ((0 : Pos.Raw).nextWhile s Char.isWhitespace).get s = 'a'let s := "a "; ((0 : Pos.Raw).nextWhile s Char.isWhitespace).get s = 'a'let s := "ba "; (Pos.Raw.nextWhile s Char.isWhitespace 0).get s = 'b'
Equations
- String.Pos.Raw.nextWhile s p i = Substring.Raw.takeWhileAux s s.rawEndPos p i
Instances For
Equations
- s.nextWhile p i = String.Pos.Raw.nextWhile s p i
Instances For
Equations
- String.Internal.nextWhileImpl s p i = String.Pos.Raw.nextWhile s p i
Instances For
Repeatedly increments a position in a string, as if by String.Pos.Raw.next, while the predicate
p returns false for the character at the position. Stops incrementing at the end of
the string or when p returns true for the current character.
Examples:
let s := " a "; (Pos.Raw.nextUntil s Char.isWhitespace 0).get s = ' 'let s := " a "; (Pos.Raw.nextUntil s Char.isAlpha 0).get s = 'a'let s := "a "; (Pos.Raw.nextUntil s Char.isWhitespace 0).get s = ' '
Equations
- String.Pos.Raw.nextUntil s p i = String.Pos.Raw.nextWhile s (fun (c : Char) => !p c) i
Instances For
Equations
- s.nextUntil p i = String.Pos.Raw.nextUntil s p i
Instances For
If pat matches a prefix of s, returns the remainder. Returns none otherwise.
Use String.dropPrefix to return the slice
unchanged when pat does not match a prefix.
This is a cheap operation because it does not allocate a new string to hold the result.
To convert the result into a string, use String.Slice.copy.
This function is generic over all currently supported patterns.
Examples:
"red green blue".dropPrefix? "red " == some "green blue".toSlice"red green blue".dropPrefix? "reed " == none"red green blue".dropPrefix? 'r' == some "ed green blue".toSlice"red green blue".dropPrefix? Char.isLower == some "ed green blue".toSlice
Equations
- s.dropPrefix? pat = s.toSlice.dropPrefix? pat
Instances For
If pat matches a suffix of s, returns the remainder. Returns none otherwise.
Use String.dropSuffix to return the slice
unchanged when pat does not match a prefix.
This is a cheap operation because it does not allocate a new string to hold the result.
To convert the result into a string, use String.Slice.copy.
This function is generic over all currently supported patterns.
Examples:
"red green blue".dropSuffix? " blue" == some "red green".toSlice"red green blue".dropSuffix? "bluu " == none"red green blue".dropSuffix? 'e' == some "red green blu".toSlice"red green blue".dropSuffix? Char.isLower == some "red green blu".toSlice
Equations
- s.dropSuffix? pat = s.toSlice.dropSuffix? pat
Instances For
If pat matches a prefix of s, returns the remainder. Returns s unmodified
otherwise.
Use String.dropPrefix? to return none when pat does not match a prefix.
This is a cheap operation because it does not allocate a new string to hold the result.
To convert the result into a string, use String.Slice.copy.
This function is generic over all currently supported patterns.
Examples:
"red green blue".dropPrefix "red " == "green blue".toSlice"red green blue".dropPrefix "reed " == "red green blue".toSlice"red green blue".dropPrefix 'r' == "ed green blue".toSlice"red green blue".dropPrefix Char.isLower == "ed green blue".toSlice
Equations
- s.dropPrefix pat = s.toSlice.dropPrefix pat
Instances For
Equations
- s.stripPrefix pre = (s.dropPrefix pre).toString
Instances For
Equations
- s.stripPrefix pre = s.dropPrefix pre
Instances For
If pat matches a suffix of s, returns the remainder. Returns s unmodified
otherwise.
Use String.dropSuffix? to return none when pat does not match a prefix.
This is a cheap operation because it does not allocate a new string to hold the result.
To convert the result into a string, use String.Slice.copy.
This function is generic over all currently supported patterns.
Examples:
"red green blue".dropSuffix " blue" == "red green".toSlice"red green blue".dropSuffix "bluu " == "red green blue".toSlice"red green blue".dropSuffix 'e' == "red green blu".toSlice"red green blue".dropSuffix Char.isLower == "red green blu".toSlice
Equations
- s.dropSuffix pat = s.toSlice.dropSuffix pat
Instances For
Equations
- s.stripSuffix suff = (s.dropSuffix suff).toString
Instances For
Equations
- s.stripSuffix suff = s.dropSuffix suff