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 : ]
相關用法
- Perl ord()用法及代碼示例
- Perl chr()用法及代碼示例
- Perl log()用法及代碼示例
- Perl hex用法及代碼示例
- Perl exp用法及代碼示例
- Perl oct()用法及代碼示例
- Perl abs()用法及代碼示例
- Perl cos()用法及代碼示例
- Perl sin()用法及代碼示例
- Perl uc()用法及代碼示例
- Perl each()用法及代碼示例
- Perl int()用法及代碼示例
- Perl tell()用法及代碼示例
- Perl rename()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Perl | chop() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。