Jump to content

String matching: Difference between revisions

Added Wren
m (→‎{{header|Tailspin}}: correction to give correct answer that banana ends with na)
(Added Wren)
Line 4,048:
{{works with|Visual Basic|VB6 Standard}}
works the same as in VBA, see [[String_matching#VBA]]
 
=={{header|Wren}}==
<lang ecmascript>var s = "abracadabra"
var t = "abra"
var u = "ra"
var v = "cad"
System.print("'%(s)' starts with '%(t)' is %(s.startsWith(t))")
var indices = []
var start = 0
while (true) {
var ix = s.indexOf(u, start)
if (ix >= 0) {
indices.add(ix)
start = ix + u.count
if (start >= s.count) break
} else break
}
var contained = indices.count > 0
System.print("'%(s)' contains '%(u)' is %(contained) %(contained ? "at indices %(indices)" : "")")
System.print("'%(s)' ends with '%(v)' is %(s.endsWith(v))")</lang>
 
{{out}}
<pre>
'abracadabra' starts with 'abra' is true
'abracadabra' contains 'ra' is true at indices [2, 9]
'abracadabra' ends with 'cad' is false
</pre>
 
=={{header|XPL0}}==
9,488

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.