String matching: Difference between revisions
Content added Content deleted
(added gml) |
m (→{{header|J}}: Icon and Unicon) |
||
Line 334: | Line 334: | ||
> infixes "ab" "abcdefabqqab" |
> infixes "ab" "abcdefabqqab" |
||
[0,6,10]</lang> |
[0,6,10]</lang> |
||
== {{header|Icon}} and {{header|Unicon}} == |
|||
<lang Icon>procedure main() |
|||
write("Matching s2 :=",image(s2 := "ab")," within s1:= ",image(s1 := "abcdabab")) |
|||
write("Test #1 beginning ",if match(s2,s1) then "matches " else "failed") |
|||
writes("Test #2 all matches at positions [") |
|||
every writes(" ",find(s2,s1)|"]\n") |
|||
write("Test #3 ending ", if s1[0-:*s2] == s2 then "matches" else "fails") |
|||
end</lang> |
|||
Sample output:<pre>Matching s2 :="ab" within s1:= "abcdabab" |
|||
Test #1 beginning matches |
|||
Test #2 all matches at positions [ 1 5 7 ] |
|||
Test #3 ending matches</pre> |
|||
=={{header|J}}== |
=={{header|J}}== |