String matching: Difference between revisions

→‎{{header|AWK}}: support part 2
(awk cannot use ~ unless sanitized string, use index instead)
(→‎{{header|AWK}}: support part 2)
Line 997:
=={{header|AWK}}==
<lang AWK>#!/usr/bin/awk -f
{ pos=index($2,$1)
{
print $1 " "2, (index($2,$1)pos==1 ? "begins" : "does not begin" ), " with " $21
print $1 " " (index($2,$1) (pos ? "contains an" : "does not contain" ), " \"" $21 "\""
if (pos) {
print $1 " " ( substr($2,index($2,$1))==$1 ? "ends" : "does not end") " with " $2
l=length($1)
Pos=pos
s=$2
while (Pos){
print " " $1 " is at index", x+Pos
x+=Pos
s=substr(s,Pos+l)
Pos=index(s,$1)
}
}
print $1 " "2, ( substr($2,index($2,$1)pos)==$1 ? "ends" : "does not end"), " with " $21
}
</lang>
Anonymous user