#find(), #index(), #search()
DESCRIPTION
returns the index position (beginning at 1) of a substring within a string,
with the search starting at the given position; else 0 if not found
or:
returns the index position (beginning at 1) of a substring within a string,
with the search starting at the beginning of the string; else 0 if not found
SYNOPSIS
#find(s1,s2,i)
#index(s1,s2,i)
#search(s1,s2,i)
or:
#find(s1,s2)
#index(s1,s2)
#search(s1,s2)
ARGUMENTS
s1 - a quoted string, or string expression
s2 - a quoted string, or string expression
i - a positive integer
or:
s1 - a quoted string, or string expression
s2 - a quoted string, or string expression
EXAMPLES
# pikt +C 'output $text(#find("like finding a needle in a haystack","needle"))'
16
rule // find $user and $newuser
set #i = #index($users, "-")
set $user = $substr($users,1,#i-1)
set $newuser = $substr($users,#i+1)
rule // local & nis uname mismatch
if ! #nis
set $uname2 = $command("=ypmatch $uid passwd.byuid 2>/dev/null")
if $uname2 ne ""
set #i = #index($uname2,":")
set $uname2 = $substr($uname2,1,#if(#i,#i-1,#length($uname2)))
if $uname2 ne $uname
output mail "User $uname doesn't match the
NIS uname $uname2 for uid $uid"
endif
endif
endif
rule // dispose of ""
set #i = #index($mem, "\@")
if #i
set $user = $left($mem, #i-1)
else
set $user = $mem
endif
rule // keep resolving dotted alias until we have a simple user name
set $aliases = " "
while $user =~ "\\."
if #find($aliases, " $user ")
output mail "Can't resolve alias $user: circular reference"
next // bypass this user
else
set $aliases .= "$user "
endif
set $match = $command("=ypmatch $user aliases 2>&1")
if $match !~ "no such key"
set $user = $match
// dispose of "" that might result from
// resolving dotted alias
set #i = #index($user, "\@")
if #i
set $user = $left($user, #i-1)
endif
else
output mail "Can't resolve alias $user: no such key"
next // go on to next list member
endif
endwhile
rule // dispose of "" that might result from
// resolving dotted alias
set #i = #index($user, "\@")
if #i
set $user = $left($user, #i-1)
endif
SEE ALSO
#rfind(), #rindex(), #rsearch()
Numerical Functions
String Functions