String matching: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added syntax colouring the hard way, phix/basics) |
(Changed formatting. Added "in" test. Moved "find" at the end.) |
||
Line 2,817: | Line 2,817: | ||
<lang nim>import strutils |
<lang nim>import strutils |
||
let s = "The quick brown fox" |
|||
if startsWith( |
if s.startsWith("The quick"): |
||
echo "Starts with “The quick”." |
|||
if endsWith( |
if s.endsWith("brown Fox"): |
||
echo "Ends with “brown fox”." |
|||
if s.contains(" brown "): |
|||
echo "Contains “ brown ”." |
|||
if contains(s, " brown "): # showing the contains() proc, but could use if pos!=-1: |
|||
if "quick" in s: |
|||
⚫ | |||
echo "Contains “quick”." # Alternate form for "contains". |
|||
let pos = find(s, " brown ") # -1 if not found. |
|||
if pos >= 0: |
|||
⚫ | |||
{{out}} |
{{out}} |
||
<pre>Starts with |
<pre>Starts with “The quick”. |
||
Contains “ brown ”. |
|||
Contains “quick”. |
|||
“ brown ” is located at position: 9</pre> |
|||
=={{header|Objeck}}== |
=={{header|Objeck}}== |