Basic operations with String in DataWeave 1.0

I introduced you to DataWeave to transform data from this format to different formats in the Mule application. To do this, in addition to understanding the syntax to use in DataWeave, we need to know more operations that DataWeave supports to transform our data more easily. To begin, in this tutorial, I will list the basic operations to manipulate the String that DataWeave 1.0 supports!

Split string

To split a string in DataWeave, we need to use the square brackets, inside is the index of the character we will split.

For example, we have the payload of “Huong Dan Java” then

will return the “Huo” value as follows:

Basic operations with String in DataWeave 1.0

Reverse the string

In order to reverse the string, we only need to declare the range of values from -1 to 0:

as follows:

Basic operations with String in DataWeave 1.0

The replace function

To replace any string in DataWeave, you can use replace keyword and with keyword, simple as follows:

Result:

Basic operations with String in DataWeave 1.0

The sizeOf function

This sizeOf function supports multiple data types, depending on the data type of the parameter, the return value will be different. For String, it will return the length of the string. You declare it as follows:

Result:

Basic operations with String in DataWeave 1.0

Concat strings

In DataWeave, to join any two or more strings, we will use the “++” character, for example:

Result:

Basic operations with String in DataWeave 1.0

The trim function

Like in Java, the trim function is used to remove spaces at the beginning and the end of any string. In DataWeave, we declare this method as follows:

Result:

Basic operations with String in DataWeave 1.0

The capitalize function

DataWeave allows us to uppercase the first character of any word using capitalize function as follows:

Result:

Basic operations with String in DataWeave 1.0

The camelize function

This function helps us to edit any string follow camelcase string as follows:

Result:

Basic operations with String in DataWeave 1.0

The dasherize function

This function is used to add “-” between words in a string.

Result:

Basic operations with String in DataWeave 1.0

The pluralize method

This method is a bit peculiar because it only helps us correct a noun in English in plural form, for example, we have “mouse” in English in singular, plural will be “mice”. You use it as follows:

For example:

Basic operations with String in DataWeave 1.0

The singularize function

Similar to the pluralize function, but its purpose is the opposite:

For example:

Basic operations with String in DataWeave 1.0

The lower function

Lowercase a string:

For example:

Basic operations with String in DataWeave 1.0

The upper function

This is the capitalization for a string:

For example:

Basic operations with String in DataWeave 1.0

Add Comment