描述
此函數的操作與 index 類似,隻是它返回 STR 中最後一次出現 SUBSTR 的位置。如果指定了 POSITION,則返回該位置或該位置之前的最後一次出現。
用法
以下是此函數的簡單語法 -
rindex STR, SUBSTR, POSITION rindex STR, SUBSTR
返回值
此函數在失敗時返回 undef,否則返回最後一次出現的位置。
示例
以下是顯示其基本用法的示例代碼 -
#!/usr/bin/perl -w
$pos = rindex("abcdefghijiklmdef", "def");
print "Found position of def $pos\n";
# Use the first position found as the offset to the
# next search.
# Note that the length of the target string is
# subtracted from the offset to save time.
$pos = rindex("abcdefghijiklmdef", "def", $pos-3 );
print "Found position of def $pos\n";
執行上述代碼時,會產生以下結果 -
Found position of def 14 Found position of def 3
相關用法
- Perl rindex()用法及代碼示例
- Perl reset()用法及代碼示例
- Perl require用法及代碼示例
- Perl return()用法及代碼示例
- Perl readline用法及代碼示例
- Perl reverse()用法及代碼示例
- Perl rand用法及代碼示例
- Perl reverse用法及代碼示例
- Perl reset用法及代碼示例
- Perl rmdir用法及代碼示例
- Perl rand()用法及代碼示例
- Perl rename()用法及代碼示例
- Perl return用法及代碼示例
- Perl ref用法及代碼示例
- Perl rename用法及代碼示例
- Perl read用法及代碼示例
- Perl readpipe用法及代碼示例
- Perl readdir用法及代碼示例
注:本文由純淨天空篩選整理自 Perl rindex Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。