2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,33 +1,28 @@
|
|||
/*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 " " */
|
||||
/*REXX program demonstrates some basic character string testing (for matching). */
|
||||
parse arg A B; LB=length(B) /*obtain A and B from the command line.*/
|
||||
say 'string A = ' A /*display string A to the terminal.*/
|
||||
say 'string B = ' 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"
|
||||
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*/
|
||||
/*╔══════════════════════════════════════════════════════════════════════════╗
|
||||
║ if compare(A,B)==LB then say 'string A starts with string B' ║
|
||||
║ else say "string A doesn't start with string B" ║
|
||||
╚══════════════════════════════════════════════════════════════════════════╝*/
|
||||
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
|
||||
/*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")"
|
||||
if right(A, LB)==b then say 'string A ends with string B'
|
||||
else say "string A doesn't end with 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 until p==0
|
||||
p=pos(b, a, p+1)
|
||||
if p\==0 then Ps = Ps',' p
|
||||
end /*until ···*/
|
||||
Ps=space(strip(Ps, 'L', ","))
|
||||
times=words(Ps)
|
||||
if times==0 then say "string A doesn't contain string B"
|
||||
else say 'string A contains string B ',
|
||||
times 'time'left('s',times>1),
|
||||
"(at position"left('s', times>1) Ps')'
|
||||
|
||||
/*stick a fork in it, we're done.*/
|
||||
$=; p=0; do until p==0; p=pos(B, A, p+1)
|
||||
if p\==0 then $=$',' p
|
||||
end /*until ···*/
|
||||
$=space(strip($,'L',",")) /*elide extra blanks and leading comma.*/
|
||||
#=words($)
|
||||
if #==0 then say "string A doesn't contain string B"
|
||||
else say 'string A contains string B ' # " time"left('s', #>1),
|
||||
"(at position"left('s', #>1) $")"
|
||||
/*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue