當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。