描述
此函數返回 STR 中第一次出現 SUBSTR 的位置,從頭開始(從零開始),或者從 POSITION(如果指定)開始。
用法
以下是此函數的簡單語法 -
index STR, SUBSTR, POSITION index STR, SUBSTR
返回值
此函數在失敗時返回 -1,否則匹配字符串的位置(第一個字符從零開始)。
示例
以下是顯示其基本用法的示例代碼 -
#!/usr/bin/perl
$string = "That is test";
$index = index ($string, 'is');
print "Position of is in the string $index\n";
執行上述代碼時,會產生以下結果 -
Position of is in the string 5
相關用法
- Perl index()用法及代碼示例
- Perl int用法及代碼示例
- Perl int()用法及代碼示例
- Perl import用法及代碼示例
- Perl sin()用法及代碼示例
- Perl abs()用法及代碼示例
- Perl kill用法及代碼示例
- Perl chop()用法及代碼示例
- Perl wantarray用法及代碼示例
- Perl gmtime用法及代碼示例
- Perl exists()用法及代碼示例
- Perl split用法及代碼示例
- Perl localtime用法及代碼示例
- Perl delete()用法及代碼示例
- Perl undef用法及代碼示例
- Perl reset()用法及代碼示例
注:本文由純淨天空篩選整理自 Perl index Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。