String matching: Difference between revisions
Content added Content deleted
(String matching en Yabasic) |
(Using built-in functions) |
||
Line 1,618: | Line 1,618: | ||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |
||
===With built-in functions=== |
|||
⚫ | |||
(defun match (word str) |
<lang Emacs Lisp>(defun match (word str) |
||
(progn |
|||
(if (string-prefix-p word str) |
|||
⚫ | |||
(insert (format "%s not found in beginning of: %s\n" word str) )) |
|||
(setq pos (string-match word str) ) |
|||
(if pos |
|||
(insert (format "%s found at position %d in: %s\n" word pos str) ) |
|||
(insert (format "%s not found in: %s\n" word str) )) |
|||
(if (string-suffix-p word str) |
|||
(insert (format "%s found in end of: %s\n" word str) ) |
|||
(insert (format "%s not found in end of: %s\n" word str) )))) |
|||
⚫ | |||
(progn |
|||
(match "center" string) |
|||
(insert "\n") |
|||
(match "before" string) |
|||
(insert "\n") |
|||
(match "after" string) ) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
after found at position 14 in: before center after |
|||
after found in end of: before center after |
|||
⚫ | |||
===With regex=== |
|||
⚫ | |||
(progn |
(progn |
||
Line 1,650: | Line 1,689: | ||
</lang> |
</lang> |
||
<b>Output:</b> |
<b>Output:</b> |
||
<pre>Same output than above</pre> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|Erlang}}== |
=={{header|Erlang}}== |