{"id":1363,"date":"2008-09-11T03:45:55","date_gmt":"2008-09-11T08:45:55","guid":{"rendered":"http:\/\/www.mrc-productivity.com\/docs\/?page_id=1363"},"modified":"2023-09-26T13:11:30","modified_gmt":"2023-09-26T18:11:30","slug":"string-functions-within-freemarker","status":"publish","type":"ht_kb","link":"https:\/\/www.mrc-productivity.com\/docs\/knowledge-base\/string-functions-within-freemarker","title":{"rendered":"String Functions within Freemarker"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p>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 &#8220;User Interface&#8221; option and then &#8220;Edit Element&#8221;. Add the String Function into editor box in the correct location as desired. When completed, hit OK. Then be sure to save your application.<\/p>\n\n\n\n<p>Here is a list of many common and useful String Functions available to you within Freemarker Logic.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Sub-stringing<\/strong><\/h4>\n\n\n\n<p>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.<\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">Please remember that the 1st character of your string is the 0 position. If my <code>${row.CITY}<\/code> equals &#8220;CHICAGO&#8221;, the following expressions would give these results<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Freemarker Code<\/th><th>Result<\/th><\/tr><tr><td><code>${row.CITY?substring(1)}<\/code><\/td><td>HICAGO<\/td><\/tr><tr><td><code>${row.CITY?substring(3)}<\/code><\/td><td>CAGO<\/td><\/tr><tr><td><code>${row.CITY?substring(0,1)}<\/code><\/td><td>C<\/td><\/tr><tr><td><code>${row.CITY?substring(0,3)}<\/code><\/td><td>CHI<\/td><\/tr><tr><td><code>${row.CITY?substring(2,3)}<\/code><\/td><td>I<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Capitalize First Letter<\/strong><\/h4>\n\n\n\n<p>The function <code>${row.FIELD?cap_first}<\/code> will capitalize the first letter of your field if it is lower case. All other letters are ignored.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Un-Capitalize First Letter<\/strong><\/h4>\n\n\n\n<p>This function is the exact opposite of the one listed above, and the function and is written <code>${row.FIELD?uncap_first}<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Capitalize<\/strong><\/h4>\n\n\n\n<p>This function will capitalize the first letter in all words and un-capitalize all other letters. This function is denoted <code>${row.FIELD?capitalize}<\/code><\/p>\n\n\n\n<p>For instance, a normal output of &#8220;LOS ANGELES&#8221; would output &#8220;Los Angeles&#8221; with the ?capitalize freemarker function.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Upper Case<\/strong><\/h4>\n\n\n\n<p>This function will capitalize all letters within a string. It is noted as <code>${row.FIELD?upper_case}<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">If you are in a Maintenance application and trying to ensure upper case from the user, please use the &#8220;Do not Allow Lower Case&#8221; option from the Pre-format Level.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Lower Case<\/strong><\/h4>\n\n\n\n<p>This function will un-capitalize all letters within a string. It is noted as <code>${row.FIELD?lower_case}<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>HTML<\/strong><\/h4>\n\n\n\n<p>This function will encode all fields for use within an HTML page. For instance, if your field contains an &#8220;&amp;&#8221; it will be encoded to the HTML version of the ampersand &#8220;&amp;amp;&#8221;. 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 <code>${row.FIELD?html}<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>URL<\/strong><\/h4>\n\n\n\n<p>This function will encode all fields for use within an HTML&#8217;s URL. For instance, if your field contains an &#8220;#&#8221; it will be encoded to the URL version of the pound sign &#8220;%23;&#8221;. 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 <code>${row.FIELD?url}<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Trim<\/strong><\/h4>\n\n\n\n<p>The Freemarker Trim function will remove all leading and trailing spaces from a field. It is denoted: <code>${row.FIELD?trim}<\/code><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Length<\/strong><\/h4>\n\n\n\n<p>The Freemarker Length function will return the number of characters in the field. It is denoted: <code>${row.FIELD?length}<\/code><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Replace<\/strong><\/h4>\n\n\n\n<p>This is a very useful Freemarker function as it allows you to replace a certain value directly within your field. It is denoted:<\/p>\n\n\n\n<p><code>${row.FIELD?replace(\"FINDTHISTEXT\", \"REPLACEWITHTHISTEXT\")}<\/code><\/p>\n\n\n\n<p>For example, if my Field value was CHICAGO, and my function looked like this:<\/p>\n\n\n\n<p><code>${row.FIELD?replace(\"CAGO\", \"NA TOWN\")}<\/code><\/p>\n\n\n\n<p>My output would be &#8220;CHINA TOWN&#8221;. This is just an abbreviated list showing the most common Freemarker String Functions. A full list can be found <a href=\"https:\/\/freemarker.apache.org\/docs\/ref_builtins_string.html\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[265],"ht-kb-tag":[],"class_list":["post-1363","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-freemarker"],"_links":{"self":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/comments?post=1363"}],"version-history":[{"count":6,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1363\/revisions"}],"predecessor-version":[{"id":13202,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1363\/revisions\/13202"}],"wp:attachment":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/media?parent=1363"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb-category?post=1363"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb-tag?post=1363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}