Data.String
- Package
- purescript-strings
- Repository
- purescript/purescript-strings
Wraps the functions of Javascript's String object.
A String represents a sequence of characters.
For details of the underlying implementation, see String Reference at MDN.
#Replacement Source
newtype ReplacementA newtype used in cases to specify a replacement for a pattern.
Constructors
Instances
#charCodeAt Source
charCodeAt :: Int -> String -> Maybe IntReturns the numeric Unicode value of the character at the given index, if the index is within bounds.
charCodeAt 2 "5 €" == Just 0x20AC
charCodeAt 10 "5 €" == Nothing
#fromCharArray Source
fromCharArray :: Array Char -> StringConverts an array of characters into a string.
fromCharArray ['H', 'e', 'l', 'l', 'o'] == "Hello"
#lastIndexOf Source
lastIndexOf :: Pattern -> String -> Maybe IntReturns 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 IntReturns 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
#localeCompare Source
localeCompare :: String -> String -> OrderingCompare two strings in a locale-aware fashion. This is in contrast to
the Ord instance on String which treats strings as arrays of code
units:
"ä" `localeCompare` "b" == LT
"ä" `compare` "b" == GT
#replace Source
replace :: Pattern -> Replacement -> String -> StringReplaces the first occurence of the pattern with the replacement string.
replace (Pattern "<=") (Replacement "≤") "a <= b <= c" == "a ≤ b <= c"
#replaceAll Source
replaceAll :: Pattern -> Replacement -> String -> StringReplaces all occurences of the pattern with the replacement string.
replaceAll (Pattern "<=") (Replacement "≤") "a <= b <= c" == "a ≤ b ≤ c"
#stripPrefix Source
stripPrefix :: Pattern -> String -> Maybe StringIf 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 StringIf 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
#toCharArray Source
toCharArray :: String -> Array CharConverts the string into an array of characters.
toCharArray "Hello☺\n" == ['H','e','l','l','o','☺','\n']
#trim Source
trim :: String -> StringRemoves whitespace from the beginning and end of a string, including whitespace characters and line terminators.
trim " Hello \n World\n\t " == "Hello \n World"