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
1
2
3
4
%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
Returns a Number, representing the unicode of the first character of the specified String. This functions fails if the String is empty
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
a: charCode("b")
}
1
2
3
{
"a": 98
}
charCodeAt
charCodeAt(String, Number): Number
Returns a Number, representing the unicode of the character at the specified index. This functions if the index is invalid
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
a: charCodeAt("baby", 2)
}
1
2
3
{
"a": 98
}
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(Number): 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"
}