Freemarker String substitution operation

Source: Internet
Author: User
Tags date1 numeric value
Example
Item. userip!="">
Text=item.  Userip>
     ${?  Replace(?  Substring(text? ) Index_of(".") +1,text? index_of (".") +2)),"*")}

</#if >

Freemarker Action String

1. SUBSTRING (start,end) intercepts a substring from a string start: Intercepts the index at the beginning of the substring, start must be greater than or equal to 0, less than or equal to end: intercept the length of the substring, end must be greater than or equal to 0, less than or equal to the length of the string, The default is the string length. Example: ${' str ' substring (0)}à results for str ${' str ' substring (1)}à result is tr ${' str ' substring (2)}à result is R ${' str '? SUBSTRING (3)}à result is $ {' str ' substring (0,0)}à result is ${' str ' substring (0,1)}à result is ${' str ' substring (0,2)}à result is St ${' str '? SUBSTRING (0,3)} à result is str

2, Cap_first the first word in the string into uppercase. ${' str '. Cap_first}à the result is str 3, uncap_first the first letter in the string into lowercase. ${' Str '. The cap_first}à result is str 4, capitalize the first letter of all words in the string into uppercase ${' str '. Capitalize}à results for Str

5. Date,time,datetime converts a string to a date such as: < #assign date1= "2009-10-12"? Date ("Yyyy-mm-dd") > < #assign date2= "9:28:20" ? Time ("HH:mm:ss") > < #assign date3= "2009-10-12 9:28:20" ("HH:mm:ss") > ${date1}à result is 2009-10-12 ${date2} À result is 9:28:20 ${date3}à result is 2009-10-12 9:28:20 Note: An error will be raised if the specified string is not properly formatted.

6. Ends_with determines whether a string ends with a substring and returns a Boolean value. ${"string"? Ends_with ("ing")? String} returns the result to True Note: Boolean values must be converted to strings to output

7. HTML is used to replace the <, >, &, and "in a string with the corresponding &lt;&gt;&quot:&amp

8, Index_of (Substring,start) finds a substring in the string, returns the index of the first character of the substring, and returns-1 if no substring is found. The start parameter is used to specify that the search starts at the index of the string, and start is a numeric value. If start is greater than the string length, the start value equals the string length, and if start is less than 0, the start value is 0. ${"string" index_of ("in") à result is 3 ${"string"? Index_of ("ab") à result is-1

9. Length return string ${"string"? Length}à result is 6

10, lower_case the string to lowercase ${"string"? Lower_case}à result is string

11, Upper_case the string to uppercase ${"string"? Upper_case}à result is string

12, contains determine whether the character contains a substring. Returns a Boolean value ${"string"? Contains ("ing")? String}à result is True Note: Boolean values must be converted to strings to output

13. Number converts a string to a digital ${"111.11"? Number}à result is 111.11

14. Replace replaces a portion of a string with a different string from left to right. ${"STRABG" replace ("AB", "in")}à result is string

15. Split a string into a set of strings using the specified delimiter

< #list "This|is|split"? Split ("|") as s> ${s} </#list > Result: This is split

16, Trim Delete string ${"string"? Trim}à result is string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.