Perl 函式 tr



描述

這不是函式。這是音譯運算子;它以 REPLACEMENTLIST 中的字元替換 SEARCHLIST 中的字元的所有出現。

語法

以下是此函式的簡單語法。

tr/SEARCHLIST/REPLACEMENTLIST/

返回值

此函式返回被替換或刪除的字元數。

示例

以下是顯示其基本用法示例的程式碼。

#!/usr/bin/perl -w

$string = 'the cat sat on the mat.';
$string =~ tr/a-z/b/d;

print "$string\n";

當執行以上程式碼時,將生成以下結果。此處選項 d 用於刪除匹配的字元。

 b b   b.
perl_function_references.htm
廣告
© . All rights reserved.