String matching: Difference between revisions

(→‎{{header|Kotlin}}: updated kotlin to find ALL occurrences of the string)
Line 4,325:
</syntaxhighlight>
 
=={{header|RPL}}==
===Determining if the first string starts with second string===
Returns 1 if the strings match accordingly, 0 otherwise.
"ABCDEF" "ABC"
≪ SWAP OVER SIZE 1 SWAP SUB == ≫ EVAL
===Determining if the first string contains the second string at any location===
Returns the position of the first character of the second string in the first string if the strings match accordingly, 0 otherwise.
"ABCDEF" "BCD"
POS
===Determining if the first string ends with the second string===
Returns 1 if the strings match accordingly, 0 otherwise.
"ABCDEF" "DEF"
≪ SWAP DUP2 SIZE SWAP SIZE - 1 + OVER SIZE SUB == ≫ EVAL
{{out}}
<pre>
3: 1
2: 2
1: 1
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">p 'abcd'.start_with?('ab') #returns true
1,150

edits