String Functions within Freemarker

Overview

There are many String Manipulation tools available to you within Freemarker. Often times, adding these Freemarker options will save you time, give you greater flexibility as a developer, and make your applications even more robust. To add these functions, simply open m-Painter and right click on the Field you wish to modify. Select the “User Interface” option and then “Edit Element”. Add the String Function into editor box in the correct location as desired. When completed, hit OK. Then be sure to save your application.

Here is a list of many common and useful String Functions available to you within Freemarker Logic.

Sub-stringing

While you can sub-string as a calculation, you can also sub-string using Freemarker. An example of its usefulness would be sub-stringing a portion of a common field.

Please remember that the 1st character of your string is the 0 position. If my ${row.CITY} equals “CHICAGO”, the following expressions would give these results

Freemarker CodeResult
${row.CITY?substring(1)}HICAGO
${row.CITY?substring(3)}CAGO
${row.CITY?substring(0,1)}C
${row.CITY?substring(0,3)}CHI
${row.CITY?substring(2,3)}I

Capitalize First Letter

The function ${row.FIELD?cap_first} will capitalize the first letter of your field if it is lower case. All other letters are ignored.

Un-Capitalize First Letter

This function is the exact opposite of the one listed above, and the function and is written ${row.FIELD?uncap_first}.

Capitalize

This function will capitalize the first letter in all words and un-capitalize all other letters. This function is denoted ${row.FIELD?capitalize}

For instance, a normal output of “LOS ANGELES” would output “Los Angeles” with the ?capitalize freemarker function.

Upper Case

This function will capitalize all letters within a string. It is noted as ${row.FIELD?upper_case}.

If you are in a Maintenance application and trying to ensure upper case from the user, please use the “Do not Allow Lower Case” option from the Pre-format Level.

Lower Case

This function will un-capitalize all letters within a string. It is noted as ${row.FIELD?lower_case}.

HTML

This function will encode all fields for use within an HTML page. For instance, if your field contains an “&” it will be encoded to the HTML version of the ampersand “&”. This guarantees that the browser will handle all fields correctly. This is the default encoding for all generated fields with m-Power. It is noted as ${row.FIELD?html}.

URL

This function will encode all fields for use within an HTML’s URL. For instance, if your field contains an “#” it will be encoded to the URL version of the pound sign “%23;”. This guarantees that the browser will handle all fields correctly when being passed along the URL. This is the default encoding for all fields that a user selects through the Hyperlink Wizard within m-Painter. It is noted as ${row.FIELD?url}.

Trim

The Freemarker Trim function will remove all leading and trailing spaces from a field. It is denoted: ${row.FIELD?trim}

Length

The Freemarker Length function will return the number of characters in the field. It is denoted: ${row.FIELD?length}

Replace

This is a very useful Freemarker function as it allows you to replace a certain value directly within your field. It is denoted:

${row.FIELD?replace("FINDTHISTEXT", "REPLACEWITHTHISTEXT")}

For example, if my Field value was CHICAGO, and my function looked like this:

${row.FIELD?replace("CAGO", "NA TOWN")}

My output would be “CHINA TOWN”. This is just an abbreviated list showing the most common Freemarker String Functions. A full list can be found here.

Updated on September 26, 2023

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support