Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6249621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:16:25+00:00 2026-05-24T13:16:25+00:00

I created a word counter in Ruby as a little exercise in learning Ruby.

  • 0

I created a word counter in Ruby as a little exercise in learning Ruby.

I’ve used the word counters on JavaScriptKit.com and WordCountTool.com as well as the one in Open Office Writer.

Some text produced the following results

OpenOffice: 458 words
JavaScriptKit: 453 words
WordCountTool: 455 words
Mine: 461 words

My question is this: Why do the counts differ for the same exact excerpt across all counters?

What are problems in a script that might cause an inaccurate, but still close count?

What are some ways I could improve upon my script so that it’s more accurate?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:16:25+00:00Added an answer on May 24, 2026 at 1:16 pm

    You’re really asking for a definition of a “word”, which for counting purposes could mean very different things. Let’s take your original post as an example.

    The most simplistic counting tool would be

    text.split.count                      #=> 111
    

    Yet what if you had put "Why do the counts differ/change for the same[...]"? Well, clearly “differ/change” is two words, so we should probably count forward slashes as word delimiters. In fact, just because I forgot to put a space between a full stop and the next word, doesn’t make them the same word, so let’s include full stops as delimiters too. Yet I can’t be bothered to check whether it’s a URL, so those websites you mention will have to count as two words:

    text.split(/[\s\.\/\?]+/).count       #=> 113
    

    Ok, that’s cool, but actually numbers are not technically words – and if they were spoken, 458 would be “four hundred and fifty eight” which is actually 5 words. So let’s discount them too

    text.split(/[\s\.\/\?0-9]+/).count    #=> 109
    

    You get the idea. The results you got only differed by 8 words – so clearly their definitions of a word are not all that different. But word counts are only ever a rough guide, so don’t worry about the discrepancies.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A follow on from this questions: http://stackoverflow.com/questions/3032598/rails-created-at-on-display-if-today Is it possible to output the word
I created a Word 2007 add-in project in C# that works fine on my
I created a scaffold of named pais (This is a word in Portuguese of
Using WiX (Windows Installer XML) I have created an MSI installer which installs Word
I'm programming VBA for Word 2007. I've created a UserForm which I need to
So I need to edit some text in a Word document. I created a
I've created a short text (a word) in photoshop with the blending options I
I want to read MS word files which were created using older office tool
I have created a captcha image making program with PHP <?php function word($n) {
Background: I have an extensive set of specialized VBA macros used in Word for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.