Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

To save a word you can use the follow expresion:

 

(?<word>\w+)

after that you will have the result in the group of your Match object: Match.Gropus("word").value

If you want to save more than one word, the expresion should like :

(?<desc>\w+(\s+\w+)*)

 

In order to count how many times appears: Match.Count

 

I hope it help you,

Alvaro

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...