473,385 Members | 1,824 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,385 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
Jul 21 '05 #1
4 1299
One way to do this would be to Split the String. Now it is in an array.
Then you could sort the array (Array.Sort (arrayName) and loop through
counting the number of times consecutive elements are the same.

Something like this:
Dim Words() as String = Split(TextString)
Dim Count(Words.Length -1) as Integer
Dim CountIndex as Integer = 0
Dim PrevWord as String

PrevWord = Words(0)
For i as Integer = 1 to Words.Length - 1
If Words(i) <> PrevWord Then
CountIndex +=1
End If
Count(CountIndex) += 1
PrevWord = Word(i)
Next

Hope that helps,
--
Marc Butenko
mb******@bresnan.net
"Burak" <bu*********@xpandcorp.com> wrote in message
news:b1**************************@posting.google.c om...
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

Jul 21 '05 #2
One way to do this would be to Split the String. Now it is in an array.
Then you could sort the array (Array.Sort (arrayName) and loop through
counting the number of times consecutive elements are the same.

Something like this:
Dim Words() as String = Split(TextString)
Dim Count(Words.Length -1) as Integer
Dim CountIndex as Integer = 0
Dim PrevWord as String

PrevWord = Words(0)
For i as Integer = 1 to Words.Length - 1
If Words(i) <> PrevWord Then
CountIndex +=1
End If
Count(CountIndex) += 1
PrevWord = Word(i)
Next

Hope that helps,
--
Marc Butenko
mb******@bresnan.net
"Burak" <bu*********@xpandcorp.com> wrote in message
news:b1**************************@posting.google.c om...
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

Jul 21 '05 #3
Hi Burak,

this I have answered in the vb language newsgroup.

Please send next time one message to more newsgroups.
"Crosspost" and not a lot to every newsgroup "Multipost"

Cor
Jul 21 '05 #4
Hi Burak,

this I have answered in the vb language newsgroup.

Please send next time one message to more newsgroups.
"Crosspost" and not a lot to every newsgroup "Multipost"

Cor
Jul 21 '05 #5

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

Similar topics

2
by: Angus Mackay | last post by:
I remember python having a generic tokenizer in the library. all I want is to set a list of token seperators and then read tokens out of a stream, the token seperators should be returned as...
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...
10
by: Alex | last post by:
I'm looking for a fast way to split a string into individual tokens. The typical format of the string is token1|token2|token3|...|tokenN| and the number of tokens varies (which is why i use a...
10
by: Lorenzo J. Lucchini | last post by:
Do you see any counter-indication to a token extractor in the following form? typedef int token; token ExtractToken(const char** String, char* Symbol); If it finds a valid token at the start...
0
by: Arthur | last post by:
Given a "linemess.py" file with inconsistent line ending: line 1 \r \r\n line \n tokenized as per: import tokenize f=open('linemess.py','r')
1
by: xlar54 | last post by:
Hey guys, Im writing a simple language tokenizer and Im at that point of "10 ways to do it, which is the best"... All I need it to do, is given a string, look inside it for keywords, and replace...
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. ...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.