Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using low level commands
Message
De
29/06/2004 00:21:53
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00917780
Message ID:
00918269
Vues:
7
>hi-
>
>I was some help but what I need to do is I have a text file with different chapters going from chapter 1 to chapter 11 and I neeed to write some code that takes and tells a user how many for example times the word "and" appears in each chapter.
>
>thanks
>
>james

Well, I was assuming you wanted to list all words.

If the text might eventually contain than 65,000 lines, alines() is no good, since the array is limited to 65,000 elements. Therefore, I suggest you use LLFF instead. Just read one line at a time, and count how many times the word "and" appears. Something like this (untested code):
set library to foxtools
WordToFind = "and"
TextFile = "AllChapters.txt"
WordCount = 0
fHandle = fopen(TextFile)
if fHandle < 0
  MessageBox("Can't open file.")
  return
endif
do while not feof(fHandle)
  line = fgets(fHandle)
  for i = 1 to Words(line)
    if upper(WordNum(line, i)) = upper(WordToFind)
      WordCount = WordCount + 1
    endif
  next
enddo
fclose(fHandle)
? "Number of words:", WordCount
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform