JSP string truncation class ..

Source: Internet
Author: User

Page usage:

 
<S: bean name = "com. hwtt. RBT. user. bean. cutstringbean "id =" cutstring "> <s: Param name =" str "value =" singername "/> <s: param name = "hold" value = "3"/> <s: property value = "formatstr"/> </S: bean>

Tool class:

Public class cutstringbean {private string STR; // The Private int hold of the string to be formatted; // The length of the private string end retained; // The end character private string formatstr; // formatted string Private Static final string end = ".. "; Public cutstringbean () {} Public String getstr () {return STR;} public void setstr (string Str) {This. STR = STR;} public int gethold () {return hold;} public void sethold (INT hold) {This. hold = hold;} public St Ring getend () {return end;} public void setend (string end) {This. end = end;} Public String getformatstr () {formatstr = get1_str (STR, hold, end); Return formatstr;} public void setformatstr (string formatstr) {This. formatstr = formatstr;}/*** shorten the string to the specified length, and end with the ending character ** @ Param Str * @ Param hold keep length * @ Param end string, if it is null, it is ".. "* @ return string */Public String get1_str (string STR, int H Old, string end) {If (STR = NULL | hold <1) Return ""; STR = Str. trim (); If (hold> Str. length () return STR; // int length = (hold % 2 )! = 0? Hold-1: hold; end = END = NULL? End: end; int abc123size = 0; // number and letter count if (Str. length ()> hold) {for (INT I = 0; I 

Related Article

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.