473,322 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Tokenizer question

Hello,

I will start working on a project where we have to parse a string and
store the words and the number of times each word appears.

I know you can use the Split function to split a string into words
and then I'd have to savethe words and keep a track of how many times
each one appears.

Does .NET already have a way to do this?

Thank you,

Burak
Nov 20 '05 #1
4 1030
* bu*********@xpandcorp.com (Burak) scripsit:
I will start working on a project where we have to parse a string and
store the words and the number of times each word appears.

I know you can use the Split function to split a string into words
and then I'd have to savethe words and keep a track of how many times
each one appears.

Does .NET already have a way to do this?


Split and Count ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Hi Burak,

Yes it is in the simple .Net namespace VS and also in the extended .Net VB
namespace.

Split and Split
and
Count

Cor
Nov 20 '05 #3

Hello Cor,

I ran into the same problem that this person did

From: Tina (ti**********@excite.com)
Subject: ArrayList problem
Newsgroups: microsoft.public.dotnet.languages.vb
Date: 2003-07-14 15:24:02 PST
http://groups.google.com/groups?hl=e...8&threadm=e%23
p4eYlSDHA.2188%40TK2MSFTNGP10.phx.gbl&rnum=2&prev=/groups%3Fq%3DLateboun
d%2Bassignment%2Bto%2Ba%2Bfield%26hl%3Den%26lr%3D% 26ie%3DUTF-8%26oe%3DUT
F-8%26selm%3De%2523p4eYlSDHA.2188%2540TK2MSFTNGP10.p hx.gbl%26rnum%3D2

and changed my code based on the suggestions she received.

I am having problem actually incrementing a member of the structure.

Here is my code
----------------------------
Option Strict On

Public Class test
Inherits System.Windows.Forms.Form
Public Structure countInfo
Public word As String
Public num As Integer
End Structure

Private Sub btnClick_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnClick.Click

Dim y As New ArrayList
Dim infolist As New ArrayList
Dim strIn, str As String
Dim strOut() As String
Dim i, index As Integer
Dim z1 As countInfo

' string to parse
strIn = txtInfo.Text
' parse results
strOut = strIn.Split(CChar(" "))

' save the string the first time
' next time, incement its number
For i = 0 To strOut.GetLength(0) - 1
str = CStr(strOut.GetValue(i))
index = y.IndexOf(str)
If Not index >= 0 Then
y.Add(str)
Dim newInfo As countInfo
newInfo.word = CStr(str)
newInfo.num = 1
infolist.Add(newInfo)
Else

For Each z1 In infolist
If str = z1.word Then
' z1.num gets incremented
' but the actual structure in the
' array does not
z1.num += 1
Exit For
End If
Next

End If
Next

' this works fine
For Each z In infolist
txtOut.AppendText(z.word)
txtOut.AppendText(" ")
txtOut.AppendText(CStr(z.num))
txtOut.AppendText(Constants.vbNewLine)
Next

End Sub
End Class

--------------

I would appreciate your help.

Thanks ,

Burak


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4
Hi Burak,

I did not look but made something I hope this helps?

Cor

Private Sub Y()
Dim infolist As New ArrayList
Dim info As New countInfo
Dim delimStr As String = " ,.:;#"
Dim delimiter As Char() = delimStr.ToCharArray()
Dim Cor As String = "Hello Cor, I ran into that same problem: that
this person did"
Dim Burrakstr As String = Cor.Replace(vbCrLf, "#")
Dim Burrak() As String = Burrakstr.Split(delimiter)
Burrak.Sort(Burrak)
Dim count As Integer
For Each a As String In Burrak
If a <> "" Then
If a <> info.word Then
If info.word <> "" Then
infolist.Add(info)
End If
info = New countInfo
info.word = a
info.count = 0
End If
info.count += 1
End If
Next
End Sub
Public Class countInfo
Public word As String
Public count As Integer
Public Sub New()
End Sub
End Class
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Knackeback | last post by:
task: - read/parse CSV file code snippet: string key,line; typedef tokenizer<char_separator<char> > tokenizer; tokenizer tok(string(""), sep); while ( getline(f, line) ){ ++lineNo;...
4
by: Java Guy | last post by:
This must be a classical topic -- C++ stgring tokenizer. I just switched from C to C++ ( in Unix ). It turns out that there is no existing C++ string tokenizer. Searching on the Web, I found...
18
by: Robbie Hatley | last post by:
A couple of days ago I dedecided to force myself to really learn exactly what "strtok" does, and how to use it. I figured I'd just look it up in some book and that would be that. I figured...
1
by: Karl Kobata | last post by:
Hi Fredrik, This is exactly what I need. Thank you. I would like to do one additional function. I am not using the tokenizer to parse python code. It happens to work very well for my...
2
by: ravindra singh | last post by:
i am confused about how to use the Stream Tokenizer class in java, our teacher gave us a program in which v were to use the above class. but i m not getting it. so please help me about this. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.