Word Counter

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
5 posts Page 1 of 1
Contributors
User avatar
code it
VIP - Site Partner
VIP - Site Partner
Posts: 821
Joined: Sun Oct 10, 2010 3:02 pm

Word Counter
code it
Design:
word counter.JPG
Code:
word counter code.JPG
USE THIS CODE:(THANKS MANDAI FOR THE NOTICE!
Code: Select all
       Dim spaceArray As String() = RichTextBox1.Text.Replace(vbLf, " ").Split(" "c)
        Dim wordcount As Integer = 0
        For i As Integer = 0 To spaceArray.Length - 1
            If spaceArray(i).Length > 0 Then wordcount += 1
        Next
      Label1.Text = "Words: " & wordcount
DONT USE THE ONE AT THE BOTTOM!!
Code: Select all
Public Class Form1
    Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
        Dim wordcount As Integer
        Dim num As String() = RichTextBox1.Text.Split(" ")
        wordcount = num.Length
        Label1.Text = "Words:  " & wordcount
        If RichTextBox1.Text = "" Then
            Label1.Text = "Words: 0"
        Else
            Label1.Text = "Words:  " & wordcount
        End If
    End Sub
End Class

Screenshots:
word counter2.JPG

Please +Rep me!
You do not have the required permissions to view the files attached to this post.
Last edited by code it on Sun Jan 09, 2011 9:31 pm, edited 2 times in total.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Word Counter
mandai
This counts space characters as words, plus it doesn't continue on newlines.
I made some code that will only count the words: viewtopic.php?f=32&t=3776&p=26595#p26595
Last edited by mandai on Sun Jan 09, 2011 6:28 pm, edited 1 time in total.
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: Word Counter
Axel
This checks for spaces,
if you have a string "hello world" wich contain 2 spaces, the word count will be 3 i guess
http://vagex.com/?ref=25000
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Word Counter
mandai
But a word isn't valid unless its length is greater than 0.
User avatar
code it
VIP - Site Partner
VIP - Site Partner
Posts: 821
Joined: Sun Oct 10, 2010 3:02 pm

Re: Word Counter
code it
Nevermind!

Thanks mandai for foxing my mistake
5 posts Page 1 of 1
Return to “Tutorials”