How to capitalize a string in Mule?

How to capitalize a string in Mule?

Step 1 :

Add the transform Message Component in the mule flow from component palette.

Step 2:

  In this component we can write the Dataweave script to convert string into upper case as shown below. We can click on Preview button to see the resultant of Dataweave operation.

Note:  capitalize function in Strings module of Dataweave is used to:

  • Capitalizes the first letter of each word in a string.
  • It also removes underscores between words and puts a space before each capitalized word.

Case 1:

Dataweave Expression:

%dw2.0

outputapplication/json

import * from dw::core::Strings

varfirstName= “sumitaggarwal”

capitalize(firstName)

Output:  “Sumitaggarwal”

Case 2:

Dataweave Expression:

%dw2.0

outputapplication/json

import * fromdw::core::Strings

varfirstName= “sumitaggarwal”

capitalize(firstName)

Output:  “Sumit Aggarwal”

Case 3:

Dataweave Expression:

%dw2.0

outputapplication/json

import * fromdw::core::Strings

varfirstName= “sumitAggarwal”

capitalize(firstName)

Output:  “Sumit Aggarwal”

Case 4:

Dataweave Expression:

%dw2.0

outputapplication/json

import * fromdw::core::Strings

varfirstName= “sumit_aggarwal”

capitalize(firstName)

Output:  “Sumit Aggarwal”

Reference Link: https://docs.mulesoft.com/mule-runtime/4.3/

Leave a Reply

Your email address will not be published. Required fields are marked *