/**
* 处理一个字符串 把这个字符串分成多少行 str 字符串,w 每行的宽度,f 字体
*/
public static Vector paiHang(String str, int w, Font f) {
int off = 0;
Vector v = new Vector(0);
String s = "";
for (int i = 0; i < str.length(); i++) {
s = str.substring(off, i);
if (str.charAt(i) == '/n') {
v.addElement(str.substring(off, i));
off = i + 1;
} else if (f.stringWidth(s) == w) {
v.addElement(str.substring(off, i));
off = i;
} else if (f.stringWidth(s) > w) {
v.addElement(str.substring(off, i - 1));
off = i - 1;
}
}
if (off < str.length()) {
v.addElement(str.substring(off));
}
return v;
}
字符串处理
最新推荐文章于 2024-01-15 09:14:43 发布