Novah Documentation

novah.string

Functions to work with strings.

Types

Declarations


isBlank

visibility: public
type: String -> Boolean

Returns true if this string is empty or only contains whitespace codepoints.


isNotBlank

visibility: public
type: String -> Boolean

Returns true if this string is not empty or only contains whitespace codepoints.


isEmpty

visibility: public
type: String -> Boolean

Returns true if this string is empty.


isNotEmpty

visibility: public
type: String -> Boolean

Returns true if this string is not empty.


size

visibility: public
type: String -> Int32

Returns the size of this string.


lastIndex

visibility: public
type: String -> Int32

Returns the index of the last element of this string or -1 if the string is empty. Runtime: O(1)


lowerCase

visibility: public
type: String -> String

Returns a lower case version of this string.


upperCase

visibility: public
type: String -> String

Returns a upper case version of this string.


startsWith

visibility: public
type: String -> String -> Boolean

Returns true if this string starts with prefix.


endsWith

visibility: public
type: String -> String -> Boolean

Returns true if this string ends with suffix.


substring

visibility: public
type: Int32 -> Int32 -> String -> String

Returns a substring from the given string starting at begin (inclusive) and ending in end (exclusive).


startFrom

visibility: public
type: Int32 -> String -> String

Returns a substring from the given string starting from begin.


getBytes

visibility: public
type: String -> ByteArray

Encodes this string into an array of bytes using the platform's default charset.


join

visibility: public
type: String -> List String -> String

Joins all strings in this list separated by delimiter.


strip

visibility: public
type: String -> String

Returns this string with all leading and trailing white spaces removed.


stripl

visibility: public
type: String -> String

Returns this string with all leading white spaces removed.


stript

visibility: public
type: String -> String

Returns this string with all trailing white spaces removed.


repeat

visibility: public
type: Int32 -> String -> String

Returns a string that represents the input string repeated n times.


capitalize

visibility: public
type: String -> String

Returns this string with the first character converted to upper-case and the rest converted to lower-case.


split

visibility: public
type: String -> String -> List String

Splits the string using the given regular expression. Runtime: O(n)


nth

visibility: public
type: Int32 -> String -> Option Char

Returns the character at the specified index if it exists. Runtime: O(1)


charAt

visibility: public
type: Int32 -> String -> Char

Returns the character at the specified index if it exists. Unsafe: will throw an exception in case the index is invalid. String.nth should be preferred instead of this function. Runtime: O(1)


indexOf

visibility: public
type: String -> String -> Int32

Returns the index of the given sub string inside the string or -1 if none found. Runtime: O(1)


toList

visibility: public
type: String -> List Char

Returns a list of all chars in this string. Runtime: O(n)


toSet

visibility: public
type: String -> Set Char

Returns a set of all the characters in this string. Runtime: O(n)


fromList

visibility: public
type: List Char -> String

Returns a string from a list of chars. Runtime: O(n)


map

visibility: public
type: (Char -> b) -> String -> List b

Maps a function over every char in this string. Runtime: O(n)


mapString

visibility: public
type: (Char -> Char) -> String -> String

Maps a function over every char in this string returning a new string. Runtime: O(n)


forEach

visibility: public
type: String -> (Char -> Unit) -> Unit

Executes this function for every character in the string. Runtime: O(n)


filter

visibility: public
type: (Char -> Boolean) -> String -> String

Filters chars of this string with the given predicate. Runtime: O(n)


remove

visibility: public
type: (Char -> Boolean) -> String -> String

Remove chars of this string with the given predicate. Runtime: O(n)


find

visibility: public
type: (Char -> Boolean) -> String -> Option Char

Returns the first occurrence of a char to which the predicate returns true. Runtime: O(n)


findIndex

visibility: public
type: (Char -> Boolean) -> String -> Int32

Finds the first index in this string to which predicate returns true.


drop

visibility: public
type: Int32 -> String -> String

Drops the first n chars from this string.


take

visibility: public
type: Int32 -> String -> String

Takes the first n chars from this string.


takeWhile

visibility: public
type: (Char -> Boolean) -> String -> String

Keeps taking chars from this string while the predicate holds. Runtime: O(n)


dropWhile

visibility: public
type: (Char -> Boolean) -> String -> String

Keeps droping chars from this string while the predicate holds. Runtime: O(n)


replaceChar

visibility: public
type: Char -> Char -> String -> String

Replaces all occurrences of old char with new.


replace

visibility: public
type: String -> String -> String -> String

Replaces all substrings of this string that matches target with the given replacement.


reverse

visibility: public
type: String -> String

Returns this string reversed.


count

visibility: public
type: (Char -> Boolean) -> String -> Int32

Returns the number of characters matching the given predicate. Runtime: O(n)


indices

visibility: public
type: String -> List Int32

Returns a list of all the indices from the input string. Ex:

indices "abc" // => [0, 1, 2]

lines

visibility: public
type: String -> List String

Returns a list of the lines in this string, separated by line terminators. Runtime: O(n)


stripIndent

visibility: public
type: String -> String

Finds the smallest common indentation of all lines in this string and removes it. Blank lines will be removed. Does not preserve line endings.