The functions described here are packaged in the Strings module. The module is included with the Mule runtime, but you must import it to your DataWeave code by adding the line import dw::core::Strings to your header.
Example
%dw 2.0
import dw::core::Strings
---
Strings::pluralize("box")
Functions
Camelize
camelize(String): String
Returns the provided string in camel case.
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
a: camelize("customer"),
b: camelize("customer_first_name"),
c: camelize("customer name")
}
1
2
3
4
5
{
"a": "customer",
"b": "customerFirstName",
"c": "customer name"
}
Capitalize
capitalize(String): String
Returns the provided string with every word starting with a capital letter and no underscores. It also replaces underscores with spaces and puts a space before each capitalized word.
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
a: capitalize("customer"),
b: capitalize("customer_first_name"),
c: capitalize("customer NAME"),
d: capitalize("customerName")
}
1
2
3
4
5
6
{
"a": "Customer",
"b": "Customer First Name",
"c": "Customer Name",
"d": "Customer Name"
}
CharCode
charCode(String): Number | Null
Returns the Number of the code of the specified String. The string must be of one character.
CharCodeAt
charCodeAt(String, Number): Number | Null
Returns the Number of the code of the specified String at certain char position.
Dasherize
dasherize(String): String
Returns the provided string with every word separated by a dash.
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
a: dasherize("customer"),
b: dasherize("customer_first_name"),
c: dasherize("customer NAME")
}
1
2
3
4
5
{
"a": "customer",
"b": "customer-first-name",
"c": "customer-name"
}
FromCharCode
fromCharCode(Number): String
Returns the String of the specified Number code.
Ordinalize
ordinalize(String): String
Returns the provided numbers set as ordinals.
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
a: ordinalize(1),
b: ordinalize(8),
c: ordinalize(103)
}
1
2
3
4
5
{
"a": "1st",
"b": "8th",
"c": "103rd"
}
Pluralize
pluralize(String): String
Returns the provided string transformed into its plural form.
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
a: pluralize("box"),
b: pluralize("wife"),
c: pluralize("foot")
}
1
2
3
4
5
{
"a": "boxes",
"b": "wives",
"c": "feet"
}
Singularize
singularize(String): String
Returns the provided string transformed into its singular form.
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
a: singularize("boxes"),
b: singularize("wives"),
c: singularize("feet")
}
1
2
3
4
5
{
"a": "box",
"b": "wife",
"c": "foot"
}
Underscore
underscore(String): String
Returns the provided string with every word separated by an underscore.
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
a: underscore("customer"),
b: underscore("customer-first-name"),
c: underscore("customer NAME")
}
1
2
3
4
5
{
"a": "customer",
"b": "customer_first_name",
"c": "customer_NAME"
}