Data.String.CodeUnits
- Package
- purescript-strings
- Repository
- purescript/purescript-strings
#stripPrefix Source
stripPrefix :: Pattern -> String -> Maybe String
If the string starts with the given prefix, return the portion of the string left after removing it, as a Just value. Otherwise, return Nothing.
stripPrefix (Pattern "http:") "http://purescript.org" == Just "//purescript.org"
stripPrefix (Pattern "http:") "https://purescript.org" == Nothing
#stripSuffix Source
stripSuffix :: Pattern -> String -> Maybe String
If the string ends with the given suffix, return the portion of the
string left after removing it, as a Just
value. Otherwise, return
Nothing
.
stripSuffix (Pattern ".exe") "psc.exe" == Just "psc"
stripSuffix (Pattern ".exe") "psc" == Nothing
#fromCharArray Source
fromCharArray :: Array Char -> String
Converts an array of characters into a string.
fromCharArray ['H', 'e', 'l', 'l', 'o'] == "Hello"
#toCharArray Source
toCharArray :: String -> Array Char
Converts the string into an array of characters.
toCharArray "Hello☺\n" == ['H','e','l','l','o','☺','\n']
#countPrefix Source
countPrefix :: (Char -> Boolean) -> String -> Int
Returns the number of contiguous characters at the beginning of the string for which the predicate holds.
countPrefix (_ /= ' ') "Hello World" == 5 -- since length "Hello" == 5
#lastIndexOf Source
lastIndexOf :: Pattern -> String -> Maybe Int
Returns the index of the last occurrence of the pattern in the
given string. Returns Nothing
if there is no match.
lastIndexOf (Pattern "c") "abcdc" == Just 4
lastIndexOf (Pattern "c") "aaa" == Nothing
#lastIndexOf' Source
lastIndexOf' :: Pattern -> Int -> String -> Maybe Int
Returns the index of the last occurrence of the pattern in the
given string, starting at the specified index
and searching backwards towards the beginning of the string.
Returns Nothing
if there is no match.
lastIndexOf' (Pattern "a") 1 "ababa" == Just 0
lastIndexOf' (Pattern "a") 3 "ababa" == Just 2
lastIndexOf' (Pattern "a") 4 "ababa" == Just 4
#slice Source
slice :: Int -> Int -> String -> Maybe String
Returns the substring at indices [begin, end)
.
If either index is negative, it is normalised to length s - index
,
where s
is the input string. Nothing
is returned if either
index is out of bounds or if begin > end
after normalisation.
slice 0 0 "purescript" == Just ""
slice 0 1 "purescript" == Just "p"
slice 3 6 "purescript" == Just "esc"
slice (-4) (-1) "purescript" == Just "rip"
slice (-4) 3 "purescript" == Nothing
#splitAt Source
splitAt :: Int -> String -> { after :: String, before :: String }
Splits a string into two substrings, where before
contains the
characters up to (but not including) the given index, and after
contains
the rest of the string, from that index on.
splitAt 2 "Hello World" == { before: "He", after: "llo World"}
splitAt 10 "Hi" == { before: "Hi", after: ""}
Thus the length of (splitAt i s).before
will equal either i
or
length s
, if that is shorter. (Or if i
is negative the length will be
0.)
In code:
length (splitAt i s).before == min (max i 0) (length s)
(splitAt i s).before <> (splitAt i s).after == s
splitAt i s == {before: take i s, after: drop i s}
- Modules
- Data.
Char - Data.
Char. Gen - Data.
String - Data.
String. CaseInsensitive - Data.
String. CodePoints - Data.
String. CodeUnits - Data.
String. Common - Data.
String. Gen - Data.
String. NonEmpty - Data.
String. NonEmpty. CaseInsensitive - Data.
String. NonEmpty. CodePoints - Data.
String. NonEmpty. CodeUnits - Data.
String. NonEmpty. Internal - Data.
String. Pattern - Data.
String. Regex - Data.
String. Regex. Flags - Data.
String. Regex. Unsafe - Data.
String. Unsafe