package tablecloth-native
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=0c71dd4035d6fa4978baabc3c932dba3
sha512=44ba09f1ff43e61403703cc244e91e0f8062bd9da998f031430d701a4de148b02878f7f881303f6ded261176f21926ab5ba00a313510ed8e2d2f252b3fd00054
doc/tablecloth-native/Tablecloth/String/index.html
Module Tablecloth.String
Functions for working with "strings"
Functions for working with "strings"
Create
Strings literals are created with the "double quotes" syntax.
Create a string from an Array of characters.
Note that these must be individual characters in single quotes, not strings of length one.
Examples
String.fromArray [||] = ""String.fromArray [|'a'; 'b'; 'c'|] = "abc"Create a string from a List of characters.
Note that these must be individual characters in single quotes, not strings of length one.
Examples
String.fromList [] = ""String.fromList ['a'; 'b'; 'c'] = "abc"Create a string by repeating a string count time.
Exceptions
If count is negative, String.repeat throws a RangeError exception.
Examples
String.repeat ~count:3 "ok" = "okokok"String.repeat ~count:3 "" = ""String.repeat ~count:0 "ok" = ""Create a string by providing a length and a function to choose characters.
Returns an empty string if the length is negative.
Examples
String.initialize 8 ~f:(Fun.constant '9') = "999999999"Basic operations
The index operator version of getAt
Note Currently this is only supported by the OCaml syntax.
Examples
("Doggie".String.?[3]) = Some 'g'String.("Doggie".?[9]) = NoneReverse a string
Note This function does not work with Unicode characters.
Examples
String.reverse "stressed" = "desserts"Extract a substring from the specified indicies.
See Array.slice.
Query
Returns the length of the given string.
Warning if the string contains non-ASCII characters then length will not equal the number of characters
Examples
String.length "abc" = 3See if the second string starts with prefix
Examples
String.startsWith ~prefix:"the" "theory" = trueString.startsWith ~prefix:"ory" "theory" = falseSee if the second string ends with suffix.
Examples
String.endsWith ~suffix:"the" "theory" = falseString.endsWith ~suffix:"ory" "theory" = trueCheck if one string appears within another
Examples
String.includes "team" ~substring:"tea" = trueString.includes "team" ~substring:"i" = falseString.includes "ABC" ~substring:"" = trueTest if the first letter of a string is upper case.
Note This function works only with ASCII characters, not Unicode.
Examples
String.isCapitalized "Anastasia" = trueString.isCapitalized "" = falseModify
Drop count characters from the left side of a string.
Examples
String.dropLeft ~count:3 "abcdefg" = "defg"String.dropLeft ~count:0 "abcdefg" = "abcdefg"String.dropLeft ~count:7 "abcdefg" = ""String.dropLeft ~count:(-2) "abcdefg" = "fg"String.dropLeft ~count:8 "abcdefg" = ""Drop count characters from the right side of a string.
Examples
String.dropRight ~count:3 "abcdefg" = "abcd"String.dropRight ~count:0 "abcdefg" = "abcdefg"String.dropRight ~count:7 "abcdefg" = ""String.dropRight ~count:(-2) "abcdefg" = "abcdefg"String.dropRight ~count:8 "abcdefg" = ""Returns the index of the first occurrence of string or None if string has no occurences of string
Examples
String.indexOf "Hello World World" "World" = Some 6 String.indexOf "Hello World World" "Bye" = None Returns the index of the last occurrence of string or None if string has no occurences of string
Examples
String.indexOfRight "Hello World World" "World" = Some 12 String.indexOfRight "Hello World World" "Bye" = None val insertAt : string -> index:int -> value:t -> stringInsert a string at index.
The character previously at index will now follow the inserted string.
Examples
String.insertAt ~value:"**" ~index:2 "abcde" = "ab**cde"String.insertAt ~value:"**" ~index:0 "abcde" = "**abcde"String.insertAt ~value:"**" ~index:5 "abcde" = "abcde**"String.insertAt ~value:"**" ~index:(-2) "abcde" = "abc**de"String.insertAt ~value:"**" ~index:(-9) "abcde" = "**abcde"String.insertAt ~value:"**" ~index:9 "abcde" = "abcde**"val insert_at : string -> index:int -> value:t -> stringConverts all upper case letters to lower case.
Note This function works only with ASCII characters, not Unicode.
Examples
String.toLowercase "AaBbCc123" = "aabbcc123"Converts all lower case letters to upper case.
Note This function works only with ASCII characters, not Unicode.
Examples
String.toUppercase "AaBbCc123" = "AABBCC123"Converts the first letter to lower case if it is upper case.
Note This function works only with ASCII characters, not Unicode.
Examples
String.uncapitalize "Anastasia" = "anastasia"Converts the first letter of s to lowercase if it is upper case.
Note This function works only with ASCII characters, not Unicode.
Examples
String.uncapitalize "den" = "Den"Removes leading and trailing whitespace from a string
Examples
String.trim " abc " = "abc"String.trim " abc def " = "abc def"String.trim "\r\n\t abc \n\n" = "abc"Like trim but only drops characters from the beginning of the string.
Like trim but only drops characters from the end of the string.
Pad a string up to a minimum length
If the string is shorted than the proivded length, adds with to the left of the string until the minimum length is met
Examples
String.padLeft "5" 3 ~with_:"0" = "005"Pad a string up to a minimum length
If the string is shorted than the proivded length, adds with to the left of the string until the minimum length is met
Examples
String.padRight "Ahh" 7 ~with_:"h" = "Ahhhhhh"Deconstruct
Divide a string into a list of strings, splitting whenever on is encountered.
Examples
String.split ~on:"/" "a/b/c" = ["a"; "b"; "c"]
String.split ~on:"--" "a--b--c" = ["a"; "b"; "c"]
String.split ~on:"/" "abc" = ["abc"]
String.split ~on:"/" "" = [""]
String.split ~on:"" "abc" = ["a"; "b"; "c"]Iterate
Like Array.fold but the elements are Chars
Convert
Returns an Array of the individual characters in the given string.
Examples
String.toArray "" = [||]String.toArray "abc" = [|'a'; 'b'; 'c'|]Returns a List of the individual characters in the given string.
Examples
String.toList "" = []String.toList "abc" = ['a'; 'b'; 'c']Compare
Compare two strings. Strings use 'dictionary' ordering. 1 Also known as lexicographical ordering.
Examples
String.compare "Z" "A" = 1String.compare "Be" "Bee" = -1String.compare "Pear" "pear" = 1String.compare "Peach" "Peach" = 0The unique identity for Comparator