perl的index命令

发布时间:2020-02-21编辑:脚本学堂
perl的index命令,英文原样奉送,大家慢慢研读。

perl的index命令,英文原样奉送,大家慢慢研读。
Syntax
index STR, SUBSTR, POSITION
index STR, SUBSTR
Definition and Usage
Returns the position of the first occurrence of SUBSTR in STR, starting at the beginning (starting at zero), or from POSITION if specified.
Return Value
    -1 on failure otherwise Position of matching string (starting at zero for the first character).

Example

Try out following example:
 

复制代码 代码如下:
#!/usr/bin/perl
$string = "That is test";
$index = index ($string, 'is');
print "Position of is in the string $indexn";



It produces following result
Position of is in the string 5