Freemarker operation string

Source: Internet
Author: User
Tags date1

1. substring (START, end) truncates a substring from a string.
Start: The index starting from the substring. Start must be greater than or equal to 0 and less than or equal to end.
End: Specifies the length of a substring. The end value must be greater than or equal to 0 and smaller than or equal to the string length. If this parameter is omitted, the default value is the string length.
Example:
$ {'Str '? Substring (0)} à result: Str
$ {'Str '? Substring (1)} à returns tr
$ {'Str '? Substring (2)} à result: R
$ {'Str '? Substring (3)}. The result is
$ {'Str '? Substring ()}. The result is
$ {'Str '? Substring (0, 1)} à result: S
$ {'Str '? Substring ()} à result is St
$ {'Str '? Substring ()} à returns Str

2. cap_first converts the first letter of the word in the string to uppercase.
$ {'Str '? Cap_first} à returns Str
3. uncap_first converts the initial character of the first word in the string to lowercase.
$ {'Str '? Cap_first} à returns Str
4. capitalize converts the first letter of all words in the string to uppercase.
$ {'Str '? Capitalize} à result: Str

5. convert a string to a date by date, time, and datetime.
For example:
<# Assign date1 = "2009-10-12 "? Date ("yyyy-mm-dd")>
<# Assign date2 = "9:28:20 "? Time ("HH: mm: SS")>
<# Assign date3 = "9:28:20 "? Time ("HH: mm: SS")>
$ {Date1} à result:
The result of $ {date2} à is 9:28:20.
$ {Date3} à result: 9:28:20
Note: If the specified string format is incorrect, an error is thrown.

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

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

8. index_of (substring, start) searches for a substring in the string and returns the index of the first character of the substring. If no substring is found,-1 is returned.
The start parameter is used to specify the index where the string is searched. The start parameter is a numerical value.
If start is greater than the string length, the start value is equal to the string length. 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 returns the string length $ {"string "? Length}. The result is 6.

10. Use lower_case to convert the string to lowercase.
$ {"String "? Lower_case} à result: String

11. upper_case converts strings into uppercase letters.
$ {"String "? Upper_case} à result: String

12. Contains determines whether a character contains a substring. Returns a Boolean value.
$ {"String "? Contains ("ing ")? String}. The result is true.
Note: boolean values must be converted to strings before output.

13. number converts a string to a number.
${111.11 "? Number}. The result is 111.11.

14. Replace replaces a portion of the string with another string from left to right.
$ {"Strabg "? Replace ("AB", "in")}. The result is string.

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

<# List "This | is | split "? Split ("|") as S>
$ {S}
</# List>
Result:
This
Is
Split

16. Trim deletes the leading and trailing spaces of a 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.