String matching: Difference between revisions
Content added Content deleted
(added ocaml) |
|||
Line 342: | Line 342: | ||
loc = "abab".find("ab") #returns 0 |
loc = "abab".find("ab") #returns 0 |
||
loc = "abab".find("ab",loc+1) #returns 2</lang> |
loc = "abab".find("ab",loc+1) #returns 2</lang> |
||
=={{header|REXX}}== |
|||
Extra coding was added to take of using plurals in the messages. |
|||
<lang rexx> |
|||
/*REXX program to show some basic character string testing. */ |
|||
parse arg a b |
|||
say 'string A=' a |
|||
say 'string B=' b |
|||
say |
|||
if left(A,length(b))==b then say 'string A starts with string B' |
|||
else say "string A doesn't start with string B" |
|||
say |
|||
p=pos(b,a) |
|||
if p\==0 then say 'string A contains string B (starting in position' p")" |
|||
else say "string A doesn't contains string B" |
|||
say |
|||
if right(A,length(b))==b then say 'string A ends with string B' |
|||
else say "string A doesn't end with string B" |
|||
say |
|||
Ps='' |
|||
p=0 |
|||
do forever until p==0 |
|||
p=pos(b,a,p+1) |
|||
if p\==0 then Ps=Ps',' p |
|||
end |
|||
Ps=space(strip(Ps,'L',",")) |
|||
times=words(Ps) |
|||
if times\==0 then say 'string A contains string B', |
|||
times 'time'left('s',times>1), |
|||
"(at position"left('s',times>1) Ps')' |
|||
else say "string A doesn't contains string B" |
|||
</lang> |
|||
Output when the following is specified (five Marx brothers): |
|||
<br><br> |
|||
++++++++ |
|||
<pre style="height:30ex;overflow:scroll"> |
|||
@@@@@@@@@@@@@@@@@@ |
|||
</pre> |
|||
Output when the following is specified: |
|||
<br><br> |
|||
++++++++ |
|||
<pre style="height:30ex;overflow:scroll"> |
|||
@@@@@@@@@@@@@@@@@@ |
|||
</pre> |
|||
Output when the following is specified: |
|||
<br><br> |
|||
++++++++ |
|||
<pre style="height:30ex;overflow:scroll"> |
|||
@@@@@@@@@@@@@@@@@@ |
|||
</pre> |
|||
Output when the following is specified: |
|||
<br><br> |
|||
++++++++ |
|||
<pre style="height:30ex;overflow:scroll"> |
|||
@@@@@@@@@@@@@@@@@@ |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |