Anonymous user
String matching: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments, elided a boxed comment.
(Added Wren) |
m (→{{header|REXX}}: added/changed whitespace and comments, elided a boxed comment.) |
||
Line 3,402:
Extra coding was added to take care of using plurals in the last output message.
<lang rexx>/*REXX program demonstrates some basic character string testing (for matching). */
parse arg A B
say 'string A = '
say 'string B = '
say copies('░', 70) /*display a line separator (fence). */
LB= length(B) /*get the length of string B in bytes*/
if left(A, LB)==B then say 'string A starts with string B'
else say "string A doesn't start with string B"
say /* [↓] another method using COMPARE BIF*/
p= pos(B, A)▼
▲p=pos(B, A)
if p==0 then say "string A doesn't contain string B"
else say 'string A contains string B (starting in position' p")"
say
if right(A, LB)==
else say "string A doesn't end with string B"
say
$=; p= 0; do until
if p\==0 then $= $',' p
end /*until*/
#= words($) /*obtain number of words in $ string.*/
if #==0 then say "string A doesn't contain string B"
else say 'string A contains string B ' # " time"left('s', #>1),
{{out|output|text= when the following is specified (the five Marx brothers): <tt> Chico_Harpo_Groucho_Zeppo_Gummo p </tt> }}
<pre>
|