It has an error Explode? (Documentation Bugs and Problems)

by lrcvs, Sunday, February 17, 2013, 10:39 (1527 days ago)

Hi, Jim:

It has an error "Explode"?

Watch this:

#::::::::::::::::::::::::::::::::::::::::::::::::::::
#>>> your "Explode", the test !!!

cls
cp = 0
ce = 0
graphvisible false
z$ = " while AZUCAR for next AGUA VINO$ and input"
print
print z$
print "long = " + string ( length (z$))
w$ = explode(upper (z$)," ")
print "words in w$ = " + w$[?]
print "ERROR !!!, there is = " + w$[?]
print
for n= 0 to w$[?]- 1
print w$[n]
next n
print ":::::::::::::::::::::::::::::::::::::::::::"
print

#:::::::::::::::::::::::::::::::

#>>> My "Explode", my test !!!


l = length (z$)
p = 0
r = 0
y$ = ""
for n = 1 to l
x$ = mid(z$,n,1)
if n = 1 and x$ <> " " then y$ = x$
if n = 1 and x$ = " " then r = 1

if n > 1 and x$ <> " " then r = 0

if n > 1 and x$ <> " " and r = 0 then
y$ = y$ + x$
end if

if n > 1 and x$ = " " and r = 0 then
y$ = y$ + " "
r = 1
end if



next n

#::::::::::::::::::::::::::::::::::::::
print
print "This is Ok!"
print
print y$
print "long = " + string ( length (y$))
w$ = explode(upper (y$)," ")
print "words in w$ = " + w$[?]
print
for n= 0 to w$[?]- 1
print w$[n]
next n
end

end

Window output

by lrcvs, Sunday, February 17, 2013, 10:42 (1527 days ago) @ lrcvs

#window output


while AZUCAR for next AGUA VINO$ and input
long = 77
words in w$ = 43
ERROR !!!, there is = 43


WHILE


AZUCAR

FOR

NEXT

AGUA

VINO$


AND
INPUT

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


This is Ok!

while AZUCAR for next AGUA VINO$ and input
long = 42
words in w$ = 8

WHILE
AZUCAR
FOR
NEXT
AGUA
VINO$
AND
INPUT

Window output

by Jim ⌂ @, Russell, KY, Sunday, February 17, 2013, 22:27 (1527 days ago) @ lrcvs

Actually the EXPLODE function is acting correctly. If the delimiter was a comma like in the string "a,,c,,,f" this should be an array of six items with three of them the empty string. In your example the spaces are delimiters and there are words of zero length between the spaces.

Your code is trimming the leading and trailing spaces and removing the duplicates (as mine is below) but that is not the behavior I was expecting. I guess the documentation should be updated to reflect the possibility of zero length strings being between the delimiters.

Jim

###
z$ = " while AZUCAR for next AGUA VINO$ and input"
y$ = cleandelim$(z$," ")
print "long = " + string ( length (y$))
w$ = explode(upper (y$)," ")
print "words in w$ = " + w$[?]
print "ERROR !!!, there is = " + w$[?]
print
for n= 0 to w$[?]- 1
print w$[n]
next n
print ":::::::::::::::::::::::::::::::::::::::::::"
print


function cleandelim$(s$, delim$)
# remove duplicate, leading and trailing delimiters
y$ = s$
do
y2$ = y$
y$ = replace(y2$,delim$+delim$,delim$)
until y$ = y2$
if left(y$,1) = delim$ then y$ = mid(y$,2,length(y$)-1)
if right(y$,1) = delim$ then y$ = left(y$,length(y$)-1)
return y$
end function

Window output

by lrcvs, Sunday, February 17, 2013, 22:52 (1527 days ago) @ Jim

Hi, jim:

Now "Explode", is Ok!!!!

Regards

RSS Feed of thread
powered by my little forum