String matching: Difference between revisions

Changed formatting. Added "in" test. Moved "find" at the end.
m (→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics)
(Changed formatting. Added "in" test. Moved "find" at the end.)
Line 2,817:
<lang nim>import strutils
 
varlet s: string = "The quick brown fox"
if s.startsWith(s, "The quick"):
echo( "Starts with: The“The quickquick”.")
if s.endsWith(s, "brown Fox"):
echo( "Ends with: brown“brown foxfox”.")
varif pos = finds.contains(s, " brown ") # -1 if not found:
echo "Contains “ brown ”."
if contains(s, " brown "): # showing the contains() proc, but could use if pos!=-1:
if "quick" in s:
echo('"' & " brown " & '"' & " is located at position: " & $pos)</lang>
echo "Contains “quick”." # Alternate form for "contains".
 
let pos = find(s, " brown ") # -1 if not found.
if pos >= 0:
echo('"' & " brown " & '"' & " is located at position: " & $pos)</lang>
 
{{out}}
<pre>Starts with: The“The quickquick”.
EndsContains with: brown fox”.
Contains “quick”.
" brown " is located at position: 9</pre>
 
=={{header|Objeck}}==
Anonymous user