String matching: Difference between revisions

→‎{{header|J}}: faster/more efficient contains
(→‎{{header|J}}: faster/more efficient contains)
Line 61:
 
<lang j>startswith=: ] -: ({.~ #)
contains=: 1 e+. /@:E.~
endswith=:] -: ({.~ -@#)</lang>
 
Line 82:
'abab' contains 'ab'
1
'abab' I.@E.~ 'ab' NB. find starting indicies
0 2</lang>
 
Note that these verbs also apply to arrays of type other than character so:
Note that the last example was finding indices rather than determining whether or not the substring was present.
<lang j> 0 1 2 3 startswith 0 1 NB. integer
1
4.2 5.1 1.3 9 3 contains 1.3 4.2 NB. floating point
0
4.2 5.1 1.3 4.2 9 3 contains 1.3 4.2
1</lang>
 
=={{header|Java}}==
892

edits