Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

Real Word Count Utility

Does anyone have (know of) a tool or program that will allow me to count the number of words in an HTML file?  I don't want all the tags counted, just the words that would appear in the browser.  

Our situation here is that we have documents coded in HTML that have to be translated into other languages.  The rate for translations comes down to a cost per word.  It would be beneficial if we had a utility that would examine all of the HTML files in a given directory tree and give us a total word count that applies to the words that need to be translated.

Any help is greatly appreciated.

Lankford
0
lankford
Asked:
lankford
  • 5
  • 4
  • 2
  • +3
1 Solution
 
raooolCommented:
What platform?

TextPad (Wintel -- www.textpad.com) has a word count which could probably be scripted (has its own macro) to run through a batch of files. The removing tags thing could be done with a SaveAs text from a browser (or also, likely, your HTML editor). BBEdit on a Mac has a remove tags function.

Hope this helps.


On a Mac, BBedit provides 'remove tags' and I THINK it's got a word count... TextPa

Hope this helps!
0
 
talleyCommented:
We use Translation Manager V2.0 from IBM.
It has markup tables that handle the tags and do not include them in word counts.

also...
sed 's/<[^>]*>//g' index.html  will strip out tags.
0
 
ozoCommented:
that sed script could be fooled by comments, scripts, and tags spanning more than one line
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
lankfordAuthor Commented:
Let me open this up again.  I have heard that the word count feature in Microsoft Word will count the words correctly in an HTML document.  Can this funtion be used inside of a word macro and be applied to each of the files in a given directory?

Lankford
0
 
sybeCommented:
It could be written in perl quite easily. I bet that ozo (he's very active in the perl area) would not need more then half an hour to make it. Scan a whole directory at once, and for each file give the number of words, excluding the HTML-tags.
It would take me a lot more time, but still I would choose to write such a thing in perl.
0
 
talleyCommented:
In my test it was never fooled by tags over more than one line...
beginnign with < and ending with > ...
I do agree that it is not the best answer..the BEST answer is to use TM2, but most people want things for free and dislike paying for software.
0
 
mcixCommented:
You could use  

wordCount = ActiveDocument.ComputeStatistics(Statistic:=wdStatisticWords)

To obtain an accurate Word Count for an HTML document using word.

However, this method is terribly inefficient.

There is a better way using C++, Look at this article:

http://support.microsoft.com/support/kb/articles/q186/8/98.asp


0
 
mcixCommented:
It looks something like this in Word:

Public Function ComputeWordCounts(vstrPath As String,vstrSpec As String)

Dim mwrdDocument As Word.Document
Dim mstrCurrentFile As String

mstrCurrentFile = Dir(vstrPath & vstrSpec)
Do While mstrCurrentFile <> ""
    Documents.Open vstrPath & mstrCurrentFile
    wordCount = ActiveDocument.ComputeStatistics(Statistic:=wdStatisticWords)
    MsgBox ActiveDocument.Name & " has " & wordCount
    ActiveDocument.Close wdDoNotSaveChanges
    mstrCurrentFile = Dir
Loop

End Function

ComputeWordCounts "C:\SomeDirectory\" ,"*.HTM"

This will be slow, because Word will Open Each file that meets the criteria.

 
0
 
lankfordAuthor Commented:
mcix, that works for me.  Change your comment to an answer and you get the points.

Lankford
0
 
mcixCommented:
Glad it works...

Mark
0
 
lankfordAuthor Commented:
I liked your response.  

The only significant change I made was to use the Application.FileSearch object instead of the Visual Basic Dir command.  FileSearch is a little more flexible.  I was able to specify files matching *.htm and *.html and have it search sub directories too.

It is slow, but everyone around here who needs the function already has word and can let this run at night or whenever.

Thanks again for the response.

Lankford
0
 
mcixCommented:
Do you mind sharing your code?
0
 
lankfordAuthor Commented:
What is your e-mail address?  I'll mail the entire DOC file to you.

Lankford
0
 
mcixCommented:
E-Mail is:

marko_justus@hotmail.com

Thanks,

Mark
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now