{"id":1363,"date":"2008-09-11T03:45:55","date_gmt":"2008-09-11T08:45:55","guid":{"rendered":"http:\/\/www.mrc-productivity.com\/legacy\/?page_id=1363"},"modified":"2020-04-08T10:16:53","modified_gmt":"2020-04-08T15:16:53","slug":"string-functions-within-freemarker","status":"publish","type":"page","link":"https:\/\/www.mrc-productivity.com\/legacy\/freemarker\/string-functions-within-freemarker","title":{"rendered":"String Functions within Freemarker"},"content":{"rendered":"<p><!-- Begin Content --><\/p>\n<h1>String Functions Available within Freemarker<\/h1>\n<p>&nbsp;<\/p>\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 &quot;Application Field Properties&quot; option.  Add the String Function into the &quot;Representation&quot; box in the correct location.  When completed, hit OK.  Then be sure to save your application.<\/p>\n<p>Here is a list of many common and useful String Functions available to you within Freemarker Logic.<\/p>\n<p><strong>Sub-stringing<\/strong><\/p>\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<p><strong>Note:<\/strong> Please remember that the 1st character of your string is the 0 position.  If my <code>${row.CITY}<\/code> equals &quot;CHICAGO&quot;, the following expressions would give these results:<\/p>\n<table style=\"text-align:center;width:500px;border-collapse:collapse;border:1px solid black;\">\n<tbody>\n<tr>\n<th style=\"width:250px;border:3px solid black;\">Freemarker Code<\/th>\n<th style=\"width:250px;border:3px solid black;\">Result<\/th>\n<\/tr>\n<tr>\n<td style=\"border:1px solid black;\"><code>${row.CITY?substring(1)}<\/code><\/td>\n<td style=\"border:1px solid black;\">HICAGO<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid black;\"><code>${row.CITY?substring(3)}<\/code><\/td>\n<td style=\"border:1px solid black;\">CAGO<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid black;\"><code>${row.CITY?substring(0,1)}<\/code><\/td>\n<td style=\"border:1px solid black;\">C<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid black;\"><code>${row.CITY?substring(0,3)}<\/code><\/td>\n<td style=\"border:1px solid black;\">CHI<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid black;\"><code>${row.CITY?substring(2,3)}<\/code><\/td>\n<td style=\"border:1px solid black;\">I<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Capitalize First Letter<\/strong><\/p>\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<p><strong>Un-Capitalize First Letter<\/strong><\/p>\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<p><strong>Capitalize<\/strong><\/p>\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<p>For instance, a normal output of &quot;LOS ANGELES&quot; would output &quot;Los Angeles&quot; with the ?capitalize freemarker function.<\/p>\n<p><strong>Upper Case<\/strong><\/p>\n<p>This function will capitalize all letters within a string.  It is noted as <code>${row.FIELD?upper_case}<\/code>.<\/p>\n<p><strong>Note:<\/strong> If you are in a Maintenance application and trying to ensure upper case from the user, please use the &quot;Do not Allow Lower Case&quot; option from the Pre-format Level.<\/p>\n<p><strong>Lower Case<\/strong><\/p>\n<p>This function will un-capitalize all letters within a string.  It is noted as <code>${row.FIELD?lower_case}<\/code>.<\/p>\n<p><strong>HTML<\/strong><\/p>\n<p>This function will encode all fields for use within an HTML page.  For instance, if your field contains an &quot;&amp;&quot; it will be encoded to the HTML version of the ampersand &quot;&amp;amp;&quot;.  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<p><strong>URL<\/strong><\/p>\n<p>This function will encode all fields for use within an HTML&#39;s URL.  For instance, if your field contains an &quot;#&quot; it will be encoded to the URL version of the pound sign &quot;%23;&quot;.  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<p><strong>Trim<\/strong><\/p>\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<p><strong>Length<\/strong><\/p>\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<p><strong>Replace<\/strong><\/p>\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<p><code>${row.FIELD?replace(\"FINDTHISTEXT\", \"REPLACEWITHTHISTEXT\")}<\/code><\/p>\n<p>For example, if my Field value was CHICAGO, and my function looked like this:<\/p>\n<p><code>${row.FIELD?replace(\"CAGO\", \"NA TOWN\")}<\/code><\/p>\n<p>My output would be &quot;CHINA TOWN&quot;.  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\/legacy\/ref_builtins_string.html\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<p><!-- End Content --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>String Functions Available within Freemarker &nbsp; 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1352,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1363","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/pages\/1363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/comments?post=1363"}],"version-history":[{"count":3,"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/pages\/1363\/revisions"}],"predecessor-version":[{"id":9541,"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/pages\/1363\/revisions\/9541"}],"up":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/pages\/1352"}],"wp:attachment":[{"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/media?parent=1363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}