---
title: "Transforming string data"
description: "Create templates that modify and format text data, in your documents."
canonical_url: "https://resources.docmosis.com/template-tutorials/expressions-strings"
last_reviewed: 2026-09-03
---
# Transforming string data
Depending on the particular software application you are using, it might not be possible to change your data before sending it to Docmosis.
Docmosis has a range of string functions you can use within the templates to modify and format your data and achieve the desired result in your generated documents.
## Examples
To understand the functions in this example, you may find it helpful to download the supplied *ExpressionsStrings.zip* and view the example template together with the output file.
## Working with strings
Fixed or static strings in your templates should be formed using single quotes.
For example: <<cs_{gender='male'}>> This person is a Male. <<es_>>
In the above example, 'male', is a fixed string that is being used for comparison in the <<cs_ conditional section.
## Text functions
Docmosis has many text functions, for example changing case, determining text length, or replacing strings.
### Changing case
Your input data can be easily case-converted using built-in functions like:
| Function | Result |
| --- | --- |
| toLowerCase | the resulting sentence will be all lower case |
| toUpperCase | THE RESULTING SENTENCE WILL BE ALL UPPER CASE |
| titleCase | The Resulting Sentence Will Be In Title Case |
For the full list of text functions, refer to the "Text Functions" section in the Template Guide.
## Logic and transform functions
Docmosis also has expression syntax for supporting general functions, such as determining if an element is blank, or mapping data, that are also useful for manipulating text.
### Mapping your data
With Docmosis you can "map" your input data to the desired output.
For example, this:
<<{map(toUpperCase(gender), ‘M’, ’Male’, ‘F’, ‘Female’, ‘Other’)}>>
will achieve this:
| Input Data | Desired Output |
| --- | --- |
| f | Female |
| F | Female |
| m | Male |
| M | Male |
| (all other letters) | Other |
For the full list of logic and transform functions, refer to the "Logic and Transform Functions" section in the Template Guide.
## Using list data in a sentence
The example template shows how to loop through a list of values and use them in a comma-separated sentence like the one shown below.
Input Data:
"apples", "bananas", "oranges"
Desired sentence in finished document:
"My favorite fruits are apples, bananas and oranges."
The challenge is to insert a comma between values, except for the last two, and to insert the word "and" between the last two values.
To achieve this result in Docmosis, use an <<rs_ repeating section, a <<cs_ conditional section, and the built-in Docmosis variables, $itemnum and $size, as explained in the example template.
## Transforming string data - related json data
```json
{
"animal": "elephant",
"city": "los angeles",
"gender": "M",
"genderTwo": "f",
"cities": [
{
"name": "Sydney"
},
{
"name": "New York City"
},
{
"name": "London"
},
{
"name": "New Orleans"
},
{
"name": "Salt Lake City"
},
{
"name": "Paris"
}
],
"fruit": [
{
"name": "apples"
},
{
"name": "bananas"
},
{
"name": "oranges"
},
{
"name": "watermelons"
},
{
"name": "grapes"
}
]
}
```
## Transforming string data - example template syntax
**Expressions – Strings**
**String Literals**
Fixed or static strings in a template should be enclosed in single quotes.
Set a variable called $myVar to the sting ‘asdf’.
<<$myVar=’asdf’>>
What is the value of $myVar : <<$myVar>>
Single quotes should also be used for fixed or static strings used in expressions, for example in conditional sections.
Animal = <<animal>>
<<cs_{animal=’elephant’}>>
The Animal is VERY BIG.
<<else>>
The Animal is not an Elephant.
<<es_>>
**Simple String Functions**
The functions can be called with one or more parameters. The input parameters can be from your data. The output of the function will appear in the finished document.
City = <<city>>
The city above has <<{length(city)}>> characters.
A name in lower case : <<{toLowerCase(‘Bob Mathews’)}>>
A name in UPPER case : <<{toUpperCase(‘Bob Mathews’)}>>
A name in Title case : <<{titleCase(‘bob mathews’)}>>
The result of one function can be passed to another function.
Did you know that “<<{titleCase(city)}>>” has <<{round(length(city))} >> characters in it’s name.
**Advanced String Functions**
You can use a **Map** function to choose a String to display based on a field in your data.
For example your data may contain ‘M’ or ‘F’ and you want to display ‘Male’ or ‘Female’:
Gender = <<gender>>
Gender is <<{map(gender, ‘M’, ’Male’, ‘F’, ‘Female’, ‘Other’)}>>
What if the data contains upper or lower case letters : ‘m’ , ‘M’ , ‘f’ or ‘F’?
Gender = <<genderTwo>>
Gender is <<{map(toUpperCase(genderTwo), ‘M’, ’Male’, ‘F’, ‘Female’, ‘Other’)} >>
What cities start with ‘New’ or end with ‘City’
<<rs_cities>>
<<cs_{startsWith(name,’New’)}>>
<<name>> starts with ‘New’
<<es_>>
<<cs_{endsWith(name,’City’)}>>
<<name>> ends with ‘City’
<<es_>>
<<es_>>
**Comma Separated Data used in a Sentence**
Display a list of data in a comma separated sentence:
My favorite fruits are <<rs_fruit>><<name>><<cs_{($size>2)&&($itemnum<$size-1)}>>, <<es_>><<cs_{$itemnum=$size-1}>> and <<es_>><<es_>>.
*This example is using:*
- *a Repeating Section “<<rs_” to loop through all the values*
- *a Conditional Section “<<cs_” to check what item we are up to*
- *the built-in-variable $itemnum – which equals the number of the current item from the list*
- *the built-in-variable $size – which equals the number of total items in the list*
*Please refer to the Docmosis Template Guide for a full description of these features.*
*Try chancing the number of fruit in the data to see the power of this statement.*