Anonymous user
String matching: Difference between revisions
m
→{{header|REXX}}: corrected a spelling error, added comments and more whitespace within literals, use "true" IFs, removed FOREVER from DO statement.
Walterpachl (talk | contribs) m (→{{header|REXX}}: typo (contains -> contain) |
m (→{{header|REXX}}: corrected a spelling error, added comments and more whitespace within literals, use "true" IFs, removed FOREVER from DO statement.) |
||
Line 1,994:
Extra coding was added to take care of using plurals in the output messages.
<lang rexx>/*REXX program demonstrates some basic character string testing. */
parse arg a b /*obtain A and B from the C.L. */
say 'string A = ' a /*display string A to terminal.*/
say 'string B = ' b /* " " B " " */
say
if left(A,length(b))==b then say 'string A starts with string B'
say
/*another method, however a wee bit obtuse. */
/*¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
Line 2,008 ⟶ 2,006:
else say "string A doesn't start with string B"
¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬*/
/* [↑] above is a big comment. */
p=pos(b,a)
if p
say
if right(A,length(b))==b then say 'string A ends with string B'
say
Ps=''; p=0; do
p
if p\==0 then Ps = Ps',' p
end /*
Ps
times
if times
else say 'string A contains string B
/*stick a fork in it, we're done.*/</lang>
'''output''' when the following is specified (five Marx brothers): <tt> Chico_Harpo_Groucho_Zeppo_Gummo p </tt>
<pre>
string A = Chico_Harpo_Groucho_Zeppo_Gummo
string B = p
string A doesn't start with string B
string A contains string B (starting in position 10)
string A doesn't end with string B
string A contains string B 3 times (at positions 10, 23, 24)
</pre>
'''output''' when the following is specified: <tt> Chico_Harpo_Groucho_Zeppo_Gummo Z </tt>
<pre>
string A = Chico_Harpo_Groucho_Zeppo_Gummo
string B = Z
string A doesn't start with string B
string A contains string B (starting in position 21)
string A doesn't end with string B
string A contains string B 1 time (at position 21)
</pre>
'''output''' when the following is specified: <tt> Chico_Harpo_Groucho_Zeppo_Gummo Chi </tt>
<pre>
string A = Chico_Harpo_Groucho_Zeppo_Gummo
string B = Chi
string A starts with string B
string A contains string B (starting in position 1)
string A doesn't end with string B
string A
</pre>
'''output''' when the following is specified: <tt> Chico_Harpo_Groucho_Zeppo_Gummo mmo </tt>
<
string B = mmo▼
▲string B= mmo
string A doesn't start with string B
string A contains string B (starting in position 29)
string A ends with string B
string A contains string B 1 time (at position 29)
</pre>
|