[Gambas-user] Wordcount in a TextEdit

Benoit Minisini gambas at ...1...
Fri Apr 18 08:18:59 CEST 2008


On vendredi 18 avril 2008, Ron Onstenk wrote:
> On Friday 18 April 2008 01:31, MaxVK wrote:
> > Hi, I'm trying to get a wordcount function in a textedit control, but I'm
> > having some real problems.
> >
> > I'm trying to count the spaces and full stops etc, but my wordcounts are
> > inaccurate to say the least.
> >
> > Has anyone implemented such a function, or have any tips that could help
> > me along?
> >
> > Cheers
> >
> > Max
>
> sNoCR=string.replace(sTextin,"\r"," ") 'replace control character by spaces
> sNoLF=string.replace(sNoCR,"\l"," ")
> 'repeat for tabs ("\t") and any other you can enter
>
> asWords=split(sNoLF," ")  'split on spaces
> ' count(asWords) is dirty word count
> ' two or more spaces give also a entry on split but are empty
>
> count=0
> for i=0 to count(asWords) ' loop array for non space entries
>   if trim( asWords[i] ) <> "" then count=count+1
> next
>

You can tell Split() not to return void entries with its fourth optional 
argument.

Regards,

-- 
Benoit Minisini




More information about the User mailing list