String matching: Difference between revisions
Content added Content deleted
(→{{header|Fortran}}: added modern fortran version) |
m (→TXR Lisp: Drop @(do ...); rename script to cmatch2.tl) |
||
Line 2,757: | Line 2,757: | ||
===TXR Lisp=== |
===TXR Lisp=== |
||
<lang |
<lang txrlisp>(tree-case *args* |
||
((big small) |
|||
(tree-case *args* |
|||
(cond |
|||
( |
((< (length big) (length small)) |
||
(put-line `@big is shorter than @small`)) |
|||
((str= big small) |
|||
(put-line `@big and @small are equal`)) |
|||
((match-str big small) |
|||
(put-line `@small is a prefix of @big`)) |
|||
((match-str big small -1) |
|||
(put-line `@small is a suffix of @big`)) |
|||
(t (let ((pos (search-str big small))) |
|||
( |
(if pos |
||
(put-line `@small occurs in @big at position @pos`) |
|||
(put-line `@small does not occur in @big`)))))) |
|||
⚫ | |||
(put-line `@small does not occur in @big`)))))) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
{{out}} |
{{out}} |
||
<pre>$ txr cmatch2. |
<pre>$ txr cmatch2.tl x |
||
usage: txr cmatch2. |
usage: txr cmatch2.tl <bigstring> <smallstring> |
||
$ txr cmatch2. |
$ txr cmatch2.tl x y z |
||
usage: txr cmatch2. |
usage: txr cmatch2.tl <bigstring> <smallstring> |
||
$ txr cmatch2. |
$ txr cmatch2.tl catalog cat |
||
cat is a prefix of catalog |
cat is a prefix of catalog |
||
$ txr cmatch2. |
$ txr cmatch2.tl catalog log |
||
log is a suffix of catalog |
log is a suffix of catalog |
||
$ txr cmatch2. |
$ txr cmatch2.tl catalog at |
||
at occurs in catalog at position 1 |
at occurs in catalog at position 1 |
||
$ txr cmatch2. |
$ txr cmatch2.tl catalog catalogue |
||
catalog is shorter than catalogue |
catalog is shorter than catalogue |
||
$ txr cmatch2. |
$ txr cmatch2.tl catalog catalog |
||
catalog and catalog are equal |
catalog and catalog are equal |
||
$ txr cmatch2. |
$ txr cmatch2.tl catalog dog |
||
dog does not occur in catalog</pre> |
dog does not occur in catalog</pre> |
||