String matching: Difference between revisions
Content added Content deleted
m (→{{header|J}}) |
(→{{header|J}}: faster/more efficient contains) |
||
Line 61: | Line 61: | ||
<lang j>startswith=: ] -: ({.~ #) |
<lang j>startswith=: ] -: ({.~ #) |
||
contains=: |
contains=: +./@:E.~ |
||
endswith=:] -: ({.~ -@#)</lang> |
endswith=:] -: ({.~ -@#)</lang> |
||
Line 82: | Line 82: | ||
'abab' contains 'ab' |
'abab' contains 'ab' |
||
1 |
1 |
||
'abab' I.@E.~ 'ab' |
'abab' I.@E.~ 'ab' NB. find starting indicies |
||
0 2</lang> |
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}}== |
=={{header|Java}}== |