当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Perl chop()用法及代码示例


Perl中的chop()函数用于从输入字符串中删除最后一个字符。

用法: chop(String)

参数:
String :这是输入字符串,其最后一个字符被删除。


返回值:最后删除的字符。

示例1:

#!/usr/bin/perl 
  
# Initialising a string 
$string = "GfG is a computer science portal"; 
  
# Calling the chop() function 
$A  = chop($string); 
  
# Printing the chopped string and  
# removed character 
print " Chopped String is : $string\n"; 
print " Removed character is : $A\n";


输出:

Chopped String is : GfG is a computer science porta
Removed character is : l

示例2:

#!/usr/bin/perl 
  
# Initialising a string 
$string = "[1, 2, 3]"; 
  
# Calling the chop() function 
$A  = chop($string); 
  
# Printing the chopped string and  
# removed character 
print " Chopped String is : $string\n"; 
print " Removed character is : $A\n";

输出:

Chopped String is : [1, 2, 3
Removed character is : ]


相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Perl | chop() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。