Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Thu Sep 19, 2002 10:16 am Post subject: String evaluation - word count |
|
|
Well another one for handling strings: This routine counts the number of words in a string, as defined by the delimiter supplied
(variable %%delim)
Greetz
Dr. Dread
| Code: |
list create,1
%%string = " This is a test string holding 11 words in all (space-delimited) "
%%delim = " "
%%pos = @pos(%%delim,%%string)
if @greater(%%pos,0)
rem If the string starts out with one or more delim chars, we need to trim it
repeat
%%pos = @pos(%%delim,%%string)
if @equal(%%pos,1)
%%string = @strdel(%%string,1,)
end
until @greater(%%pos,1)
rem If the string ends with one or more delim chars, we need to trim it also
repeat
if @equal(@substr(%%string,@len(%%string)),%%delim)
%%string = @strdel(%%string,@len(%%string))
end
until @not(@equal(@substr(%%string,@len(%%string)),%%delim))
repeat
%%pos = @pos(%%delim,%%string)
list add,1,@substr(%%string,1,@sum(%%pos,@pred(@len(%%delim))))
%%string = @strdel(%%string,%%pos,@sum(%%pos,@pred(@len(%%delim))))
until @equal(@pos(%%delim,%%string), 0)
end
info The string holds @succ(@count(1)) word(s)
list close,1
exit
|
_________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|