Some practical graphical user interface methods

Source: Internet
Author: User
Tags split stringbuffer

This function has been applied repeatedly to multiple mobile phone application software platforms

Usage: Parameter definition: str--string to split

font--fonts

rowmaxw--width per line after split

Support designator:

\ n Line Change

\ t Inserts a space of two Chinese characters length

public static final string[] Clipstring (String str,font font,int rowmaxw) {
if (str = null)
return null;      
if (Rowmaxw < Font.charwidth (' ha '))
Rowmaxw = font.charwidth (' ha ');
int strid = 0;
int roww = 0;
Vector strmanager = new vector ();
Char ch = ';  
while (Str.length () > Strid) {
ch = str.charat (Strid);
  Switch (CH)
{
case ' \ n ':
Strmanager.addelement (str.substring (0,strid));
str = str.substring (strid+1);
Roww = 0;
Strid = 0;
break;   
case ' \ t ':
StringBuffer sb = new StringBuffer (str);
Sb.deletecharat (Strid);
Sb.insert (Strid, "");
str = sb.tostring ();
break;   
Default:
if (Roww + font.charwidth (ch) > Rowmaxw) {
Strmanager.addelement (str.substring (0,strid));
str = str.substring (Strid);
Roww = 0;
Strid = 0;   
}else{
Roww + = font.charwidth (ch);
strid++;
}
}
}
Strmanager.addelement (str);
string[] O_str = new string[strmanager.size ()];
Strmanager.copyinto (O_STR);
return o_str;
}

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.