String matching: Difference between revisions
Using built-in functions
(String matching en Yabasic) |
(Using built-in functions) |
||
Line 1,618:
=={{header|Emacs Lisp}}==
===With built-in functions===
<lang Emacs Lisp>▼
<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) )
center found at position 7 in: before center after▼
center not found in end of: before center after▼
before found in beginning of: before center after▼
before found at position 0 in: before center after▼
before not found in end of: before center after▼
after found at position 14 in: before center after
after found in end of: before center after
</pre>▼
===With regex===
▲<lang Emacs Lisp>(defun match (word str)
(progn
Line 1,650 ⟶ 1,689:
</lang>
<b>Output:</b>
<pre>Same output than above</pre>
▲<pre>
▲center not found in beginning of: before center after
▲center found at position 7 in: before center after
▲center not found in end of: before center after
▲before found in beginning of: before center after
▲before found at position 0 in: before center after
▲before not found in end of: before center after
▲after not found in beginning of: before center after
▲after found at position 14 in: before center after
▲after found in end of: before center after
▲</pre>
=={{header|Erlang}}==
|