Jump to content

Longest common substring: Difference between revisions

m
→‎{{header|REXX}}: added whitespace.
m (→‎{{header|REXX}}: added whitespace.)
Line 1,268:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
LCsubstr: procedure; parse arg x,y,,$; #=0 0 /*LCsubstr: Longest Common Substring. */
L= length(x); w= length(y) /*placeholders for string length of X,Y*/
if w<L then do; parse arg y,x; L=w w /*switch X & Y if Y is shorter than X*/
end
do j=1 for L while j<=L-# /*step through start points in string X*/
do k=L-j+1 to # by -1 /*step through string lengths. */
_= substr(x, j, k) /*extract a possible common substring. */
if pos(_, y)\==0 then if k># then do; $= _; #= k; end
end /*k*/ /* [↑] determine if string _ is longer*/
end /*j*/ /*#: the current length of $ string.*/
Cookies help us deliver our services. By using our services, you agree to our use of cookies.