首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Perl 字符串定长瓜分

2012-08-22 
Perl 字符串定长分割Perl 字符串按照给定的长度分割并返回数组?sub splitStr {my ( $strtmp, $length )

Perl 字符串定长分割

Perl 字符串按照给定的长度分割并返回数组

?

sub splitStr {my ( $strtmp, $length ) = @_;my $strLength = length $strtmp;my @results;for ( my $i = 0 ; $i < $strLength ; $i += $length ) {#if length reach the bound , just resturn the left ones if ( $strLength < ( $i + $length ) ) {push @results, substr( $strtmp, $i );}else {push @results, substr( $strtmp, $i, $length );}}return \@results;}

热点排行