描述

此函数返回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

参考链接

https://www.learnfk.com/perl/perl-index.html