Anonymous user
String matching: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, added whitespace to the output, boxed a couple of statements (as a comment), simplified some IFs, made capitalization of A and B variables, used the improved {{out}} template.
m (added indentation for the numbered bullet points.) |
m (→{{header|REXX}}: added/changed comments and whitespace, added whitespace to the output, boxed a couple of statements (as a comment), simplified some IFs, made capitalization of A and B variables, used the improved {{out}} template.) |
||
Line 2,438:
=={{header|REXX}}==
Extra coding was added to take care of using plurals in the output messages.
<lang rexx>/*REXX program demonstrates some basic character string testing (for matching). */
parse arg
say 'string A = '
say 'string B = '
say
if left(A,
/*╔══════════════════════════════════════════════════════════════════════════╗
║ else say "string A doesn't start with string B" ║▼
╚══════════════════════════════════════════════════════════════════════════╝*/
if p==0 then say "string A doesn't contain string B"▼
else say 'string A contains string B (starting in position' p")"▼
say
/*another method, however a wee bit obtuse. */▼
▲if compare(a,b)==length(b) then say 'string A starts with string B'
▲ else say "string A doesn't start with string B"
▲ /* [↑] above is a big comment. */
▲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,length(b))==b then say 'string A ends with string B'
▲ p=pos(b, a, p+1)
else say 'string A contains string B ' # " time"left('s',
/*stick a fork in it, we're all done. */</lang>▼
▲times=words(Ps)
{{out
▲if times==0 then say "string A doesn't contain string B"
▲ else say 'string A contains string B ',
▲ "(at position"left('s', times>1) Ps')'
▲ /*stick a fork in it, we're done.*/</lang>
▲{{out}} when the following is specified (five Marx brothers): <tt> Chico_Harpo_Groucho_Zeppo_Gummo p </tt>
<pre>
string A = Chico_Harpo_Groucho_Zeppo_Gummo
Line 2,482 ⟶ 2,477:
string A doesn't end with string B
string A contains string B 3 times (at positions 10, 23, 24)
</pre>
{{out
<pre>
string A = Chico_Harpo_Groucho_Zeppo_Gummo
Line 2,495 ⟶ 2,490:
string A doesn't end with string B
string A contains string B 1 time (at position 21)
</pre>
{{out
<pre>
string A = Chico_Harpo_Groucho_Zeppo_Gummo
Line 2,508 ⟶ 2,503:
string A doesn't end with string B
string A contains string B 1 time (at position 1)
</pre>
{{out
<pre>
string A = Chico_Harpo_Groucho_Zeppo_Gummo
Line 2,521 ⟶ 2,516:
string A ends with string B
string A contains string B 1 time (at position 29)
</pre>
|