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.

Transform
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")
}
Output
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.

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"
}

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"
}

FromCharCode

fromCharCode(Number): String

Returns the String of the specified Number code.

Ordinalize

ordinalize(String): 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"
}

Pluralize

pluralize(String): String

Returns the provided string transformed into its plural form.

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

Singularize

singularize(String): String

Returns the provided string transformed into its singular form.

Transform
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")
}
Output
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.

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"
}