Strings (dw::core::Strings)

This module contains helper functions for working with strings.

To use this module, you must import it to your DataWeave code, for example, by adding the line import * from dw::core::Strings to the header of your DataWeave script.

Functions

Name Description

appendIfMissing

Appends the suffix to the end of the text if the text does not already ends with the suffix.

camelize

Returns a string in camel case based on underscores in the string.

capitalize

Capitalizes the first letter of each word in a string.

charCode

Returns the Unicode for the first character in an input string.

charCodeAt

Returns the Unicode for a character at the specified index.

collapse

Collapses the string into substrings of equal characters.

countCharactersBy

Counts the number of times an expression that iterates through each character in a string returns true.

countMatches

Counts the number of matches in a string.

dasherize

Replaces spaces, underscores, and camel-casing in a string with dashes (hyphens).

everyCharacter

Checks whether a condition is valid for every character in a string.

first

Returns characters from the beginning of a string to the specified number of characters in the string, for example, the first two characters of a string.

fromCharCode

Returns a character that matches the specified Unicode.

hammingDistance

Returns the Hamming distance between two strings.

isAlpha

Checks if the text contains only Unicode digits. A decimal point is not a Unicode digit and returns false.

isAlphanumeric

Checks if the text contains only Unicode letters or digits.

isLowerCase

Checks if the text contains only lowercase characters.

isNumeric

Checks if the text contains only Unicode digits.

isUpperCase

Checks if the text contains only uppercase characters.

isWhitespace

Checks if the text contains only whitespace.

last

Returns characters from the end of string to a specified number of characters, for example, the last two characters of a string.

leftPad

The specified text is left-padded to the size using the padText. By default padText is " ".

levenshteinDistance

Returns the Levenshtein distance (or edit distance) between two strings.

lines

Returns an array of lines from a string.

mapString

Applies an expression to every character of a string.

ordinalize

Returns a number as an ordinal, such as 1st or 2nd.

pluralize

Pluralizes a singular string.

prependIfMissing

Prepends the prefix to the beginning of the string if the text does not already start with that prefix.

remove

Removes all occurrences of a specified pattern from a string.

repeat

Repeats a text the number of specified times.

replaceAll

Replaces all substrings that match a literal search string with a specified replacement string.

reverse

Reverses sequence of characters in a string.

rightPad

The specified text is right-padded to the size using the padText. By default padText is " ".

singularize

Converts a plural string to its singular form.

someCharacter

Checks whether a condition is valid for at least one of the characters or blank spaces in a string.

substring

Returns a substring that spans from the character at the specified from index to the last character before the until index.

substringAfter

Gets the substring after the first occurrence of a separator. The separator is not returned.

substringAfterLast

Gets the substring after the last occurrence of a separator. The separator is not returned.

substringBefore

Gets the substring before the first occurrence of a separator. The separator is not returned.

substringBeforeLast

Gets the substring before the last occurrence of a separator. The separator is not returned.

substringBy

Splits a string at each character where the predicate expression returns true.

substringEvery

Splits a string into an array of substrings equal to a specified length.

underscore

Replaces hyphens, spaces, and camel-casing in a string with underscores.

unwrap

Unwraps a given text from a wrapper text.

withMaxSize

Checks that the string length is no larger than the specified maxLength. If the string’s length is larger than the maxLength, the function cuts characters from left to right, until the string length meets the length limit.

words

Returns an array of words from a string.

wrapIfMissing

Wraps text with wrapper if that wrapper is missing from the start or end of the given string.

wrapWith

Wraps the specified text with the given wrapper.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub