String matching: Difference between revisions
Content added Content deleted
No edit summary |
(Add Seed7 example) |
||
Line 1,240: | Line 1,240: | ||
loc = "abab".indexOf("ab") //returns 0 |
loc = "abab".indexOf("ab") //returns 0 |
||
loc = "abab".indexOf("ab", loc+1) //returns 2</lang> |
loc = "abab".indexOf("ab", loc+1) //returns 2</lang> |
||
=={{header|Seed7}}== |
|||
<lang seed7>$ include "seed7_05.s7i"; |
|||
const proc: main is func |
|||
local |
|||
var integer: position is 0; |
|||
begin |
|||
writeln(startsWith("abcd", "ab")); # write TRUE |
|||
writeln(endsWith("abcd", "zn")); # write FALSE |
|||
writeln(pos("abab", "bb") <> 0); # write FALSE |
|||
writeln(pos("abab", "ab") <> 0); # write TRUE |
|||
writeln(pos("abab", "bb")); # write 0 |
|||
position := pos("abab", "ab"); |
|||
writeln(position); # position is 1 |
|||
position := pos("abab", "ab", succ(position)); |
|||
writeln(position); # position is 3 |
|||
end func;</lang> |
|||
Output: |
|||
<pre> |
|||
TRUE |
|||
FALSE |
|||
FALSE |
|||
TRUE |
|||
0 |
|||
1 |
|||
3 |
|||
</pre> |
|||
=={{header|Standard ML}}== |
=={{header|Standard ML}}== |