[Solved] Word count

Discuss the word processor
Post Reply
Stef
Posts: 2
Joined: Tue Apr 15, 2008 3:00 am

[Solved] Word count

Post by Stef »

Hi,

Here's somebody can tell me if it's possible to know how many caracters with and without spaces in a text. Actually, the statistics availables in the Word count (Tools) don't make any difference between the caracters with and without spaces.

Thanks!
Last edited by Hagar Delest on Tue Jul 01, 2008 1:29 pm, edited 1 time in total.
Reason: tagged the thread as Solved.
the_importer
Posts: 1
Joined: Tue Apr 15, 2008 4:08 am

Re: Word count

Post by the_importer »

Well I don't know if there is a real solution, but while you're waiting for an answer you might want to try a work around.

OpenOffice counts your spaces as characters, now if your goal is to NOT include spaces, you might want to remove them and then do a word count. When you hit Ctrl+F, you'll do a word find, but you can also replace or remove words or spaces. Simply make a space in the "Search For" box (first box) and then click on the replace all button. This will remove all single spaces, allowing you to count the exact number of characters in your document.

When you're done, undo the space removal by hitting Ctrl+Z or close your document WITHOUT Saving. Do NOT save your document with the space removed or you'll end up having to redo them one at the time :P

Hope that helps for now
Stef
Posts: 2
Joined: Tue Apr 15, 2008 3:00 am

Re: Word count

Post by Stef »

Thanks a lot for the tip, The_Importer.

It's very appreciated.

Good night!
bhmt
Posts: 78
Joined: Wed Nov 28, 2007 7:35 pm

Re: Word count

Post by bhmt »

That seems like a good answer.

As an aside, if you make a "replace all," the dialog will tell you how many replacements were made, so in your example you would know how many spaces were found and replaced in the text.

If you need to count how many times a word or phrase appears, put it in both the Find and in the Replace windows and select Replace All. Nothing will really get changed in your text (I "copy/paste" between the windows to ensure I don't introduce a typo), but it will indicate how many were "replaced."
Phil
Volunteer
Posts: 802
Joined: Fri Nov 30, 2007 5:35 pm
Location: Germany

Re: Word count

Post by Phil »

I recommend using the Alternative dialog Find & Replace for Writer. It's a great extension anyway! 8-)
It allows to use regular expressions (like does the standard writer search dialog as well), but it additionally allows to count the hits without modifying the text.
Also, there are pop-down menus for standard regular expression searches, i.e. Any letter and Any space for your case.
Some more information about regular expressions is found in the OOoAuthors Users Manual. Detailed information is found in Wikipedia.

KR, phil
OOo 3.0.1 & DEV-3.1 • WinXP pro 32-bit + SP3 + current patches
Looking for OpenOffice-related information? Try the search engine on OpenOfficeNinja - a great tool!
My favorite extension: Alt. Find & Replace for Writer. All you need and much more...
OOo 2.4.X on Ms Windows XP
User avatar
Hagar Delest
Moderator
Posts: 32665
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Word count

Post by Hagar Delest »

Here is a small macro taken from the French forum and adapted to your needs:

Code: Select all

Sub CharactersCount
Dim oDoc      As Object
Dim oText     As Object
Dim b         As String
Dim t         As String
' Counters definition
Dim sc         As Long   ' space
Dim lc         As Long   ' letter
Dim dc         As Long   ' digit
Dim rc         As Long   ' carriage return
Dim oc         As Long   ' other

oDoc = ThisComponent
oText = oDoc.Text

' Get the counts
n = 1
Do
	t = Mid(oText.String, n, 64000)
	n = n + 64000
    For p = 1 To Len(t)
    	Select Case Mid(t, p, 1)
        	Case "a" To "z", "A" To "Z"    ' letters
            	lc = lc + 1
			Case " ", Chr(9)          ' tabulation and spaces
            	sc = sc + 1
			Case "0" To "9"             ' digits
				dc = dc + 1
			Case Chr(13)             ' carriage returns
				rc = rc + 1
			Case Chr(10)
			' to be ignored
			Case else
				oc = oc + 1
		End Select
	Next p
Loop While Len(t) = 64000

' Show the results
t = "Alphanumerical characters: " & Str( lc + dc ) & Chr(13) & Chr(10) _
& "Spaces and tabulations : " & Str(sc) & Chr(13) & Chr(10) _
& "Others (punctuation, ...): " & Str(oc) & Chr(13) & Chr(10) _
& "Total: " & Str(lc+dc+sc+oc) & Chr(13) & Chr(10) _
& "Total minus spaces and tabs: " & Str(lc+dc-sc)
MsgBox t,0,"Custom count"

End Sub
here is how it looks like (type 'dt' and hit F3 then run the macro):
Custom count.png
 Edit: July 24th, 2008: cleaned some code. 
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
cassyjanek
Posts: 1
Joined: Sat Jul 19, 2008 8:24 am

Re: [Solved] Word count

Post by cassyjanek »

Thank you, The Importer. Pressing CTRL+F, counting, then CTRL+Z seems a very natty (good) solution which I will certainly use.

The makers of Open Office have done a wonderful job with loads of Word-like applications, surely it cannot be beyond them to include a character count without spaces in the next version of Open Office.

Cheers,
Cassyjanek
OOo 2.4.X on Ms Windows XP
User avatar
floris v
Volunteer
Posts: 4431
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: [Solved] Word count

Post by floris v »

It probably wouldn't, but this is a user to user forum and developers don't come here.
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
User avatar
r4zoli
Volunteer
Posts: 2882
Joined: Mon Nov 19, 2007 8:23 pm
Location: Budapest, Hungary

Re: [Solved] Word count

Post by r4zoli »

Hagar's macro working only with simple documents. If documents consist TOC, all count results are zero. Can anybody show me the solution?
AOO 4.0 and LibO 4 on Win 8
Hungarian forum co-admin
User avatar
Hagar Delest
Moderator
Posts: 32665
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: [Solved] Word count

Post by Hagar Delest »

Could you upload a sample file?
It works fine for me even if there is a ToC.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
r4zoli
Volunteer
Posts: 2882
Joined: Mon Nov 19, 2007 8:23 pm
Location: Budapest, Hungary

Re: [Solved] Word count

Post by r4zoli »

Andrew Pitonyak's Base macro file, gives zeros. http://www.pitonyak.org/database/AndrewBase.odt, and http://dba.openoffice.org/specification ... signer.odt.
I tried it with OOo 2.4.1 Novell under openSuSE 11.0, and 2.4.1 and Dev300m26 under WinXP, same results.

Tried others and others look like working, but same strange differences in characters totals and Tools>Word counts results, with http://dba.openoffice.org/specification ... atting.odt, with macro: 14118, word count 8447 .
AOO 4.0 and LibO 4 on Win 8
Hungarian forum co-admin
User avatar
Hagar Delest
Moderator
Posts: 32665
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: [Solved] Word count

Post by Hagar Delest »

Right, the macro doesn't work on text longer than 65536 characters (including non printing ones).

Seems to come from oText = oDoc.Text or oText.String. One or both of these variables can't hold more than 65536 characters.

In my document, max char number is 65452? Since I've 42 paragraphs: 42 x 2 + 65452 = 65536 :!: (why 2 chars for each paragraph?)

NB: I've cleaned some code in the macro BTW.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Question
Posts: 15
Joined: Sun Sep 28, 2008 12:32 pm

Re: [Solved] Word count

Post by Question »

Uhh so how do i use that macro in writer?
OOo 3.2 on Windows 7
User avatar
Hagar Delest
Moderator
Posts: 32665
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: [Solved] Word count

Post by Hagar Delest »

LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
franx
Volunteer
Posts: 540
Joined: Wed Nov 12, 2008 9:25 pm
Location: FRA 'n' QXB

Re: [Solved] Word count

Post by franx »

Stef wrote:[...] Here's somebody can tell me if it's possible to know how many caracters with and without spaces in a text. Actually, the statistics availables in the Word count (Tools) don't make any difference between the caracters with and without spaces. [...]
There's a difference between OOo 3.3.0 and LibO 3.3.1
(no manual check ;) ):

Tools > Word Count — OOo 3.3.0
wordcount_3_ooo330.png
wordcount_3_ooo330.png (8.47 KiB) Viewed 19342 times
Tools > Word Count — LibO 3.3.1
wordcount_3_libo331.png
wordcount_3_libo331.png (9.64 KiB) Viewed 19342 times
There will be an improvement in OOo 3.4:
Bug 89042 - Word count is incorrect with certain special characters in the text (i.e. custom quotes, dashes)
[Status: VERIFIED FIXED]

From Comment #22:
"Fixed means: word count for text with typographical quotes (single and double
quote) as listed in the attached bugdoc now do behave similar to MS Word 2007
again. This means especially that
French « savoir calculer »
is still counted as 5, since I was told the main 'feature' of the word count
implementation is to give the same result as MS Word."
LibreOffice 4.0.4 · WinXP
User avatar
Hagar Delest
Moderator
Posts: 32665
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: [Solved] Word count

Post by Hagar Delest »

franx wrote:From Comment #22:[...]
French « savoir calculer » is still counted as 5, since I was told the main 'feature' of the word count implementation is to give the same result as MS Word."
:roll: :knock:
How to prevent OOo from being better than the others...
Shame shame shame.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Post Reply