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.

Transform
1
2
3
4
5
%dw 2.0
import * from dw::core::Strings
output application/json
---
camelize("customer_first_name")
Output
1
"customerFirstName"

camelize(Null): Null

Helper function that allows camelize to work with null values.

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.

Transform
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")
}
Output
1
2
3
4
5
6
{
  "a": "Customer",
  "b": "Customer First Name",
  "c": "Customer Name",
  "d": "Customer Name"
}

capitalize(Null): Null

Helper function that allows capitalize to work with null values.

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

Transform
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
  a: charCode("b")
}
Output
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

Transform
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
  a: charCodeAt("baby", 2)
}
Output
1
2
3
{
  "a": 98
}

dasherize

dasherize(String): String

Returns the provided string with every word separated by a dash.

Transform
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")
}
Output
1
2
3
4
5
{
  "a": "customer",
  "b": "customer-first-name",
  "c": "customer-name"
}

dasherize(Null): Null

Helper function that allows dasherize to work with null values.

fromCharCode

fromCharCode(Number): String

Returns the String of the specified Number code.

ordinalize

ordinalize(Number): String

Returns the provided numbers set as ordinals.

Transform
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)
}
Output
1
2
3
4
5
{
  "a": "1st",
  "b": "8th",
  "c": "103rd"
}

ordinalize(Null): Null

Helper function that allows ordinalize to work with null values.

pluralize

pluralize(String): String

Returns the provided string transformed into its plural form.

Transform
1
2
3
4
5
%dw 2.0
import * from dw::core::Strings
output application/json
---
 pluralize("box"),
Output
1
"boxes"

pluralize(Null): Null

Helper function that allows pluralize to work with null values.

singularize

singularize(String): String

Returns the provided string transformed into its singular form.

Transform
1
2
3
4
5
%dw 2.0
import * from dw::core::Strings
output application/json
---
singularize("boxes")
Output
1
"box"

singularize(Null): Null

Helper function that allows singularize to work with null values.

underscore

underscore(String): String

Returns the provided string with every word separated by an underscore.

Transform
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")
}
Output
1
2
3
4
5
{
  "a": "customer",
  "b": "customer_first_name",
  "c": "customer_NAME"
}

underscore(Null): Null

Helper function that allows underscore to work with null values.