rindex STR, SUBSTR, POSITION rindex STR, SUBSTR |
操作類似index,但它返回SUBSTR在STR中最後一次出現的位置。如果指定位置POSITION ,返回最後一次出現在該位置之前。
undef - 失敗時
否則的最後一次出現的位置
試試下麵的例子:
#!/usr/bin/perl -w #by www.gitbook.net $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