[Gambas-user] Wordcount in a TextEdit

Ron Onstenk ronstk at ...239...
Fri Apr 18 07:36:47 CEST 2008


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


or use the shell command 'wc' , see 'man wc'

Ron
PS, just as idea, not test for correct syntax.




More information about the User mailing list