0

Hi,

I tried so much working with this to get distinct Words and their count. I'm using ASP.NET 2.0.
And i also googled so much. I need HELP from anyone to get the required output.

1)Ex(String): The DOTNET is Very Cool! The Best.
2) Capture all the sequences like Spaces, Fullstops, Question Marks, Exclamations, Apostrophes, New Lines....(May be with RegEx?)
3)Split Words According to the above sequences
4)Get Distinct Words(Occurrences) and their count based on the input string in 1st statement.

Desired O/P:

The - 2
DOTNET - 1
Is - 1
Very - 1
Cool - 1
Best - 1


My Sample Code is as follows

ASPX:

<asp:TextBox ID="txtString" runat="server" TextMode="MultiLine" Height="100px" Width="500px"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />

CS:

//Is it possible with Dictionary
SortedList<int, string> sl = new SortedList<int, string>();

protected void btnSubmit_Click(object sender, EventArgs e)
{
//Here i'ld like to check for Space, Question Mark, New Line, Exclamation, Apostrophe,.....
//Now i'm checking only for spaces. I need the above sequences loop also.
string[] Words = txtString.Text.Split(' ');//Space Split
for (int i = 0; i < Words.Length; i++)
{
sl.Add(i, Words[i]);
}

foreach (KeyValuePair<int, string> kvp in sl)
{
//I want to print Distinct Words and their Count
Response.Write(kvp.Value + " " + kvp.Key + "<br />");
}
}

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by __avd
0

Change template parameters,

...
     SortedList<string, int> s1 = new SortedList<string, int>();
          
     foreach (string k in Words)
      {
       if (s1.ContainsKey(k))
          s1[k]++;
       else
           s1.Add(k, 1);
      }
      foreach (KeyValuePair<string, int> kvp in s1)
         Response.Write(kvp.Key + " : " + kvp.Value);
 ...
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.