![Rank: 2](images/default/star_level2.gif)
- UID
- 2033152
- 威望
- 1 点
- 金钱
- 3090 金币
- 点卡
- 0 点
|
1#
发表于 2003-9-3 17:58
| 只看该作者
一个与中文有关的问题
sub short_str{
my($str) = shift;
my($maxlen) = shift;
if ( length($str) <= $maxlen )
{
return $str;
}
if ( substr($str, 0, $maxlen) =~ /^([\000-\177]|[\200-\377][\200-\377])*(
[\
000-\177]|[\200-\377][\200-\377])$/ )
{
return substr($str, 0, $maxlen) . "...";
}
return substr($str, 0, $maxlen - 1) . "...";
}
print &short_str("我很讨厌ajal这个怪兽", 12);
print "\n";
print &short_str("我很讨厌ajal这个怪兽", 13);
print "\n";
print &short_str("ajal is not stupid", 12);
print "\n";
print &short_str("not enough?", 12);
print "\n"; |
|