|
-
Apr 28th, 2011, 06:21 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Numbering repeated words
How to delete repeated and numbering words from the text?
For example:
* in red: Words / numbers repeated
* my textbox:
" test1 test1 bb what how bb so and then yes so then so 1 3 1 4"
to get this result:
*in green: The number of times the word / number show in the text
so (3)
then (2)
1 (2)
Test1 (2)
bb (2)
what (1)
how (1)
-
Apr 28th, 2011, 06:50 AM
#2
Re: Numbering repeated words
You can create a Hashtable and use the word as a key. Everytime you find a word, add 1 to the value stored there.
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Apr 28th, 2011, 07:05 AM
#3
Re: Numbering repeated words
try this:
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String = " test1 test1 bb what how bb so and then yes so then so 1 3 1 4"
Dim occurences = From word In s.Split(New String() {" "}, StringSplitOptions.RemoveEmptyEntries) _
Group word By word Into Count()
Dim msg As String = ""
For Each o In occurences
msg &= String.Format("{0,-10} {1}{2}", o.word & ",", o.Count, Environment.NewLine)
Next
MsgBox(msg)
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 28th, 2011, 07:21 AM
#4
Hyperactive Member
Re: Numbering repeated words
I've just been playing with Regex so thought i'd add another method 
VB Code:
Imports System.Text.RegularExpressions
Imports System.Text
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Input As String = "test1 test1 bb what how bb so and then yes so then so 1 3 1 4"
Dim DupeCheck As New ArrayList
Dim Results As New StringBuilder
For Each Word As Match In Regex.Matches(Input, "\b\w+\b").Cast(Of Match).ToArray
If Not (DupeCheck.Contains(Word.Value)) Then
DupeCheck.Add(Word.Value)
Results.Append(Word.Value & ": " & Regex.Matches(Input, String.Format("\b{0}\b", Word.Value)).Cast(Of Match).ToArray.Count).AppendLine()
End If
Next
MsgBox(Input & vbCrLf & vbCrLf & Results.ToString)
End Sub
End Class
-
Apr 28th, 2011, 08:12 AM
#5
Thread Starter
Addicted Member
Re: Numbering repeated words
MarMan: Yes, but I do not manually insert the text so I do not understand how to set up random word key. thx for reply.
.paul.: thx u agin and agin . ur code is good,but if u do new line it Jamming the text. (Is it my fault - I did not say that)
jay20aiii thx agin, ur code its perfect for what I want.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|