Wikifunctions:Catalogue/String operations
Appearance

See also: WF:Catalogue/Character operations
These are functions that deal with String (Z6): A sequence of characters, and one of the fundamental Z4/Types available in the Wikifunctions system.
Evaluation
These functions perform simple tests on a text string to tell you if something else needs to be done, or they already are in an expected format.
Empty strings
- is empty string (Z10008): true if the input string is strictly empty, even without any non-printing characters, and false otherwise may return False for a non-string argument: T417631
- is not empty string (Z24331): returns true if the string in the argument is not blank
- fallback if string is empty (Z11082): returns a fallback string if the value is empty, and the value itself if not
Case and character types
- is string blank (Z10083): Checks if a string just contains whitespaces
- is numeric (Z10715): Checks if a string contains only numeric characters
- is uppercase (Z10336): checks if string is uppercase (equal to its own uppercase - so blanks and empty strings count)
- has and is uppercase (Z11349): checks if string has and is uppercase (blanks and strings without letters don't count)
- is lowercase (Z10346): checks if string is all lowercase
- has and is lowercase (Z11383): checks if string has and is lowercase (blanks and strings without letters don't count)
- is title case (Z10375): checks if string is in title case
- is pascal case (Z10363): Checks whether a string is in PascalCase.
- is camel case (Z10897): Checks whether a string is in camelCase
- is snake case (Z10324): Checks whether a string is in snake_case.
- is kebab case (Z25592): Checks whether a string is in kebab-case.
- has specified chars paired (Z11678): check if a string has correctly paired chars (for example: brackets). Specifying left and right chars (brackets) in sequence
- has all brackets paired (Z11684): check for pairing of all possible left-right paired characters, feel free to extend
- is pangram (Latin alphabet) (Z12626): checks whether a string of characters possesses every letter from the Latin alphabet at least once
Other
- is a palindrome (Z10096): test if a string is the same when read forward and backward (see Z10553 for one with Unicode grapheme support)
- has double letter (Z19170): tests whether the string has any letter (case sensitive) used twice in a row
- is square-free (Z19191): Combinatorial term. A word that avoids the pattern XX where X is any non-empty sequence of letters
- Is it a valid ISO 6709 code (Z19217): checks if a string matches ISO 6709.
- is ISO 639-1 language code (Z13482): validates whether a string is a valid ISO 639-1 language code
- is ISO 639-2 language code (Z14083): validates whether a string is a valid ISO 639-2 language code
- is heterogram (Z11573): True if no character occurs more than once
Properties and metrics
Length
Distance
Get specific characters or substrings
Anywhere in the string
At the start
- first grapheme cluster of String (Z31145): Description missing
- first N code points (Z15996): returns a string containing the specified number of character code points
- str left (Z22344): Gives the resultant <count> of characters creating a substring of characters from the start of the trimmed string. Duplicates string as needed. (same as Template:Str left on EnWp)
At the end
Comparison
| s1 ≠ s2 Q110013332 |
string inequality (Z10379) | |||
|---|---|---|---|---|
| s1 ⊇ s2 Q1332977 |
has substring (Z10070) | |||
| s1 = s2 Q842346 |
string equality (Z866) | s1 ≈ s2 Q26161438 |
case-insensitive string equality (Z10539) | |
| s ≠ <empty> | is not empty string (Z24331) | |||
| s = <empty> | is empty string (Z10008) | s ≈ <empty> | is string blank (Z10083) | |
Equality
- string equality (Z866): True if the first string and the second string are the same
- case-insensitive string equality (Z10539): returns true if both strings are the same if converted to lowercase
- string inequality (Z10379): true if two text strings are not exactly equal
- echo string except for specific replacement (Z18898): returns the same string, unless it matches a specific string when it returns a specific string
Substrings and characters
- string starts with (Z10615): returns true if the substring exists at the beginning of the string
- string ends with (Z10618): true if the substring exists at the end of the string
- string only has characters from alphabet (Z11693): check if all of the characters in the tested string are from the alphabet string
- common codepoints in strings (Z14483): true if the two strings contain any codepoints (~characters) in common
- is pangram of alphabet (Z13119): check if the string uses every letter of a specified (lowercase) alphabet
- is anagram (simple) (Z10973): test if the same characters at the same number of times are used in two strings (characters must be exact code points).
- is subword of string (Z19177): the subword is contained (in order) in the string, but may be interspersed with other letters
Length
String search
- has substring (Z10070): Check if a substring exists within another string. Case-sensitive. For a case-insensitivity support see: Z22812
- count substrings (Z14450): returns the number of times a substring occurs in a string
- position (1..=N) of first matching substring (Z31826): returns the earliest position in the first string at which the second string begins. or 0 if the first string doesn't contain the second; only identical code points count as a match
Transformation
These perform character replacements and other basic operations.
Add characters
To the start and end
To the end (suffix)
If the string doesn't already end with a specific suffix
Language-specific suffixes
- add suffix "ns" to string if it does not end with "ns" (Z18066): for Swedish
- add suffix "en" to string if it does not end with "en" (Z18050): Description missing
- add suffix "ets" to string if not end with "ets" (Z18042): Description missing
- add suffix "ens" to string if it does not end with "ens" (Z18039): Description missing
- add suffix "enas" to string if it does not end with "enas" (Z18036): E.g. huvud -> huvudenas
- add suffix "s" to string if it does not already end with "s" (Z18020): E.g. test -> tests
- add suffix "ts" to string if it does not already end with "ts" (Z18017): Description missing
- add suffix "nas" to string if it does not already end with "nas" (Z17952): Description missing
- add suffix "rnas" to string if it does not end with "rnas" (Z17942): E.g. fiende -> fiendernas
- add suffix "rna" to string if it does not end with "rna" (Z17939): E.g. fiende -> fienderna
- add suffix "r" to string if it does not end with "r" (Z17749): E.g. fiende -> fiender
- add suffix "t" to string if it does not end with "t" (Z17904): E.g. äpple -> äpplet
- add suffix "a" to string if it does not end in "a" (Z17948): Description missing
- add suffix "n" to string if it does not already end with "n" (Z17791): E.g. äpple -> äpplen
Replace characters
Anywhere in the string
- replace all substrings (Z10075): finds and replaces all instances of a substring in an input string
- replace character set (Z14613): replaces each character of the first string that appears in the second string with the corresponding character in the third string
- replace Nth character with substitution (Z29506): Description missing
- left/inner/right mark replacement (Z11492): replaces the same mark (or substring) in a string with different replacements depending on position
- general positional mark replacement (Z11501): a generalisation of Z11492 to allow different spacers and specify isolated replacement
At the end (suffix)
- replace at end (Z11178): replaces suffix with replacement if input ends with suffix; if not, returns input unchanged
- replace last character (Z27159): Description missing
Language-specific suffixes
- replace suffix "a" with "ors" (Z18092): E.g. gata -> gators
- replace suffix "a" with "ons" (Z18026): Description missing
- replace suffix "a" with "on" (Z17827): E.g. öga -> ögon
- replace suffix "a" with "orna" (Z17915): E.g. gata -> gatorna
- replace suffix "a" with "ornas" (Z17918): E.g. gata -> gatornas
- replace suffix "o" with "a" (Z27517): Description missing
- replace suffix "o" with "as" (Z27522): Description missing
- replace suffix "m" with "ns" (Z27525): Description missing
- replace suffix "ão" with "ões" (Z27534): Description missing
- replace suffix "ês" with "eses" (Z27535): Description missing
- replace suffix "ês" with "esa" (Z27536): Description missing
- replace suffix "ês" with "esas" (Z27537): Description missing
- replace suffix "l" with "is" (Z27546): Description missing
Delete or discard characters
Anywhere in the string
- remove regular spaces (Z10052): remove all regular spaces (U+0020) from a string
- remove characters in character range (Z11531): strips all characters from a codepoint block from a string
- remove characters in unicode range (Z14119): strips all characters from a codepoint block (specified by unicodes) from a string
- remove interpunction (Z11193): remove all interpunction characters
- remove all characters except Arabic numerals (Z14494): Description missing
- remove all characters except ASCII alphanumerics (Z10171): keeping [0-9A-Za-z]
- remove all characters not in second string (Z14515): leaves only the characters in string 1 that are also in string 2
- remove all characters in second string (Z14520): leaves only the characters in string 1 that are not in string 2
Duplicates
At the start and end
At the start (prefix)
- remove first N characters of string (Z14636): return the string with the first N characters removed
- String without prefix (Z31955): if a string begins with the given prefix, removes the prefix, otherwise returns the string unchanged
- discard from start of first substring (Z11410): if the substring is found in the full string, discard everything after and including the first occurrence, otherwise leave unchanged
- discard from end of first substring (Z11412): if the substring is found in the full string, discard everything after but not including the first occurrence, otherwise leave unchanged
- discard from start of last substring (Z11414): if the substring is found in the full string, discard everything after and including the last occurrence, otherwise leave unchanged
- discard from end of last substring (Z11416): if the substring is found in the full string, discard everything after but not including the last occurrence, otherwise leave unchanged
At the end (suffix)
- remove last character (Z11879): Description missing
- String without suffix (Z11170): if a string ends with the given suffix, remove the suffix, otherwise return the string unchanged
- discard until start of first substring (Z11418): if the substring is found in the full string, discard everything before but not including the first occurrence, otherwise leave unchanged
- discard until end of first substring (Z11420): if the substring is found in the full string, discard everything before and including the first occurrence, otherwise leave unchanged
- discard until start of last substring (Z11422): if the substring is found in the full string, discard everything before but not including the last occurrence, otherwise leave unchanged
- discard until end of last substring (Z11424): if the substring is found in the full string, discard everything before and including the last occurrence, otherwise leave unchanged
Whitespace
Concatenation and duplication
- join two strings (Z10000): combine two strings without any separation, one after the other
- join two strings with space (Z27182): Description missing
- concatenate many strings (Z21394): Description missing
- join list of strings with delimiter (Z12899): returns string composed of list elements separated by a given delimiter
- join list of strings with spaces (Z22504): joins a list of strings inserting a single space between each
- sentence from list of words (English conventions) (Z22514): takes a list of words, joins with spaces, collapses multiple spaces, remove spaces before punctuation, turns to sentence case and adds a full stop at the end
- enclose string (Z27385): returns a string preceded by a prefix and followed by a suffix (no separators)
- Add chars every n chars (Z19654): Broader version of Z19645
- join two strings with space unless empty (Z36804): If one string is empty, return the other. If both are empty, return empty. Otherwise join the two strings with a space in between.
- duplicate string (Z10753): takes a string and returns it duplicated
Case
- to uppercase (Z10018): Convert a string to uppercase letters
- to lowercase (Z10047): Convert a string to lowercase letters
- to Title Case (Z10251): converts a string to title case
- to PascalCase (Z10290): convert string to Pascal Case
- to camelCase (Z10816): convert string to lower camelCase,
- to snake_case (Z10281): convert string to snake case
Formatting and presentation
- turn to superscript (Z19612): Takes a text, and all characters that have a superscript version are replaced with such.
- pretty " (Z11484): replace " with pretty left-right quotes depending on position
- pretty ' (Z11490): replace ' with pretty left-right quotes depending on position
- wrap in quotes (Z35494): Wraps a text in quote marks, optionally swaps existing quotes with a lower quote level
- format digit strings with commas (Z13473): This lets you show large natural numbers, adding commas to make them more readable. It uses the International English standard of groups of 3 digits.
- pad string with leading characters to specified length (Z14770): add specified characters at the start until the string is of the required length
- string end padding (Z10108): Add string end padding
- capitalise first letter and add full stop (Z22511): turn a string of words into a sentence format, with an initial capital, and a full stop at the end.
- escape HTML (Z31471): replace &, < and > with the respective HTML entities
Other
- C-style string formatting (Z22699): Description missing
- reverse string (Z10012): Inverts the order of the characters in a String (see Z10548 for one with Unicode grapheme support)
- Infix to Postfix (Z13060): converts infix operators and operands to postfix format
- String to codepoint list (Z22717): Converts a string to a list of codepoints. Reverse at Z22693
- split string to list (Z25614): Splits a string to a list of strings based on a separator.
- convert digits to lower indices (subscript) (Z27053): Convert decimal digits to lower indices (subscript). E.g. converts simple chemical formulas (where digits are intended as lower indexes exclusively) in "ASCII" to Unicode.
- enumerate adjacent-key typos for digit string (Z32085): assumes QWERTY layout number row or numpad
Regular expressions
- number of regular expression matches with flags (Z25847): returns the number of substrings matched by the regex
- regular expression match with flags (Z25829): returns a list of strings matched by the regex
- regular expression substitute with flags (Z12316): $N for capture groups. Flags supported should at least be 'i', 'm', and 'g'.
- replace all (regex, case sensitive) (Z10193): replace characters in a string with another string according to a regex pattern
Encode and decode
- string to hex (UTF-8) (Z10366): convert string of UTF-8 characters into hexadecimal
- hex (string) to string (UTF-8) (Z10373): hex to string
- URI percent encode (Z10761): encodes certain characters using URI percent encoding syntax
- URI percent decode (Z10774): decodes a percent-encoded input string
- international morse code encode (Z10944): encodes the supplied string in morse code, separating letter encodings by spaces and words by " / "
- international morse code decode (Z10956): decodes the supplied string in morse code: separate letter encodings by spaces and words by " / "
- encode NATO phonetic alphabet code (Z10309): Encodes a Latin alphabet string using the NATO phonetic alphabet.
- decode NATO phonetic alphabet code (Z10970): case insensitive
- Base16 Encode (Z11003): Encode a string into base16
- Base16 Decode (Z11007): Decode a string from base16
- Base32 encode (Z14189): Description missing
- Base32 decode (Z14195): Decode a string from Base32
- Base64 encode (Z10057): Encode a UTF-8 string into base64.
- Base64 decode (Z10062): Decode a string from base64 (needed to demonstrate base64 encode/decode examples)
Cryptography
Caesar cipher
(alphabet needs to be specified when calling these functions)
- Caesar cipher (Latin alphabet) (Z12812): rotates letters in the Latin alphabet forward by a defined number of places
- ROT1 (Latin alphabet) (Z10846): move by one letter in the English alphabet
- ROT13 (Latin alphabet) (Z10627): encode or decode a Latin alphabet string using the ROT13 cipher ROT13 encrypt/decrypt
- ROT25 (Latin alphabet) (Z10851): move each letter one letter back in the English alphabet
- Caesar cipher (Bengali alphabets) (Z17530): Description missing
- Caesar cipher (Bengali Consonants) (Z17526): Description missing
- caesar cipher (Dagbani alphabet) (Z20669): Description missing
- encrypt Caesar (custom alphabet) (Z23869): Encrypt using Caesar's cipher with a custom alphabet. Characters not in the alphabet will not be encrypted.
Substitution ciphers
Vigenère cipher
- Vigenère cipher (Z23848): Encrypt with Vigenère cipher. Characters not in the alphabet will not be encoded.
- decrypt Vigenère (Z23851): Decrypts a text encrypted with Vigenère code. Ignores characters not in the alphabet.
- encrypt Vigenère (alphabet as list) (Z23953): Encrypt using Vigenère code with alphabet given as a list of letters.
- decrypt Vigenère (alphabet as list) (Z23956): Decrypt using Vigenère code with alphabet given as a list of letters.
Cryptographic hash functions
(would be better with types representing a stream of bytes)
- SHA-1 (Z10148): SHA-1 hash of the UTF-8 representation of a string, as a lowercase hexadecimal byte string SHA-1
- SHA-256 (Z10124): returns the hexadecimal hash of a string in SHA-256 SHA-256
- SHA-384 (Z10132): returns the hexadecimal hash of a string in SHA-384 SHA-384
- SHA-512 (Z10067): hash a string using the SHA-512 function SHA-512
Wikitext and Mediawiki string operations
- italicise in Wikitext (Z11019): wrap string with two pairs of single quotes (ABC -> ABC). Careful using this if your text has special formatting characters.
- bold in Wikitext (Z11139): bold a string by triple quoting, e.g. (ABC -> ABC). Careful if there are special characters.
- csv record to wikitable row (Z10919): Converts a validly formatted (RFC 4180) comma-separated value series into the contents of a valid wikitable row (not including the row start or row end characters) where variables are separated by '||', and any whitespace is unchanged. Be careful to validly render CSV with quoted fields and with pipes ('|') in the field.
- wrap with XML tag (Z11156): adds <tag> and </tag> around a string
- substitute mediawiki editchangetags query (Z17954): 36621225 ... ↓ ?action=editchangetags&ids%5B36621225%5D=1 ... &ids
- substitute mediawiki revisiondelete query (Z17956): 36621225 ... ↓ ?action=revisiondelete&ids%5B36621225%5D=1 ... &ids
Comma-separated values (CSV)
Color operations
Only includes functions that operate on hex triplets. For other color functions, see Wikifunctions:Catalogue/Color functions.
- mix colours (string) (Z12997): Calculates the midpoint between two colours. It prefers input in hexadecimal but also accepts basic colour names.
- convert hex colour to HSL, HSV, RGB, CMYK (Z13017): converts a hexadecimal colour code into HSL, HSV, RGB, and CMYK formats
- convert hex colour to [R,G,B] (Z17664): output is a list of three natural numbers, each between 0 and 255
- convert [R,G,B] to hex colour (Z17687): input is triplets of natural numbers between 0 and 255. output is lowercase preceded by #
- convert X11 color to hex (Z17713): converts color names to hex (including leading #) https://www.w3.org/TR/css-color-3/#svg-color
- opposite colour (Z13023): in the RGB colour space
- colour contrast ratio (Z13028): returns colour contrast ratio 'X:1' for given hex colours
- tint of color (Z18184): Mix a color with white by a given percentage
- Shade of colour (Z18189): Returns the shade of a colour by mixing it with a percentage of black.
- Tone of colour (Z18196): Returns the tone of a colour by mixing it with gray
- Analogous colour (Z18204): Returns the colours which are 30 degrees apart from the input base colour.
- Tetradic colours (square) (Z18208): Returns colours that are 90 degrees apart from the input base colour.
- Triadic colours (Z18212): Returns the input plus the two colours that are 120 degrees and 240 degrees apart from the input base colour.
- Saturation of colour (Z18263): Returns the intensity of a colour. 100% saturation means there is no addition of gray.
- Lightness of colour (Z18268): Returns the measure of how light or dark a colour is, with 0% being completely black and 100% being completely white
- Subtractive color (Z18296): Subtract the second colour from the first color.
- Additive colours (Z18300): Additively mix two hex colours using the RGB model.