Jump to content

String matching: Difference between revisions

(Added Swift example)
Line 2,680:
a indexOfSubCollection: b
a indexOfSubCollection: b startingAt: pos</lang>
 
=={{header|SNOBOL4}}==
<lang SNOBOL4> s1 = 'abcdabefgab'
s2 = 'ab'
s3 = 'xy'
OUTPUT = ?(s1 ? POS(0) s2) "1. " s2 " begins " s1
OUTPUT = ?(s1 ? POS(0) s3) "1. " s3 " begins " s1 ;# fails
 
n = 0
again s1 POS(n) ARB s2 @a :F(p3)
OUTPUT = "2. " s2 " found at position "
+ a - SIZE(s2) " in " s1
n = a :(again)
 
p3 OUTPUT = ?(s1 ? s2 RPOS(0)) "3. " s2 " ends " s1
END</lang>
{{out}}
<pre>1. ab begins abcdabefgab
2. ab found at position 0 in abcdabefgab
2. ab found at position 4 in abcdabefgab
2. ab found at position 9 in abcdabefgab
3. ab ends abcdabefgab</pre>
 
=={{header|Standard ML}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.