/usr/bin/perl# String from which Substring# is to be searched$string ="Geeks are the best";# Usingindex() to search for substring$index=index($string,'the');# Printing the position of the substringprint"Position of 'the' in the string: $index\n"; 输出: Position of 'the' in the ...
index string,substring,start_position index函数从string的左边开始运行,并搜索substring.返回找 到substring所在的位置。0是指最左边的字符,如果没有找到s ubstring,index便返回-1;如: index "Ring around the rosy","around"; #返回5 index("Pocket full of posies","ket"); #返回3 index "ddd","ff"; ...
函数名 index 调用语法 position = index (string, substring, position); 解说 返回子串substring在字符串string中的位置,如果不存在则返回-1。参数position 是可选项,表示匹配之前跳过的字符数,或者说从该位置开始匹配。 函数名 rindex 调用语法 position = rindex (string, substring, position); 解说 与index类似...
index string, substring index("Pocket full of posies", "ket") # return 3 $a="Ashes, ashes, we all fall down"; index($a,"she"); #return 1 index($a,"they") #return -l (not found) 可以给index函数规定一个字符串中开始进行搜索的起始位置,如下例子 $reindeer="dasher dancer prancer vix...
具体用法如下:The index()function is used to determine the position of a letter or a substring in a string. For example, in the word "frog" the letter "f" is in position 0, the "r" in position 1, the "o" in 2 and the "g" in 3. The substring "ro" is in ...
index 语法:index($string,$substring,position) $substring是要寻找的字符;position代表从哪一个位置开始寻找,假如省略position就从头开始找起。 说明:返回所要找寻的字符在一字符串$string中的位置,如果在字符串中找不到字符的话,则会返回-1这个值。
Substring 1 : sForGeeks Substring 2 : sForG 例子2 #!/usr/bin/perl# String to be passed$string ="GeeksForGeeks";# Callingsubstr() to find string# by passing negative index$sub_string1 =substr($string, -4);# Printing the substringprint"Substring 1 : $sub_string1\n";# Callingsubstr...
Perl进程控制函数 2010-06-01 16:58 1、进程启动函数 函数名 eval 调用语法 eval(string)解说 将string看作Perl语句执行。正确执行后,系统变量$@为空串,如果有错误,$@中为错误信息。例子 $print = "print (\"hello,world\\n\");";eval ($print);结果输出 hello, world 函数名 system 调用语法 system...
函数名 index 调用语法 position = index (string, substring, position); 解说 返回子串substring在字符串string中的位置,如果不存在则返回-1。参数position是可选项,表示匹配之前跳过的字符数,或者说从该位置开始匹配。 函数名 rindex 调用语法 position = rindex (string, substring, position); ...
my $first = index($mainstring, $substring); # find the first perl print index($mainstring, $substring, $first+1); # find the next one my $mainstring = "perl training by Taipei perl mongers"; my $substring = "perl"; my $pos; ...