Program to find how many times a word repeated in a given string using VB.net

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 165
Imports System.Collections.Generic

Imports System.Linq



Namespace ConsoleApplication2


Class Program


Private Shared Sub Main(args As String())


'Question #4: Find how many times a word repeated in a given string.

Dim lstWords As New List(Of String)() From { _
"hello", _
"this", _
"is", _
"dotnet", _
"dotnet", _
"funda", _
"is", _
"is" _
}











(From g In From word In lstWordsGroup word By wordNew With { _
Key .Words = g.Key, _
Key .WordsRepeated = If((g.Count() - 1) = 0, [String].Concat("Word ", g.Key, " has never repeated"), [String].Concat("Word ", g.Key, " repeated ", g.Count(), " times")) _
}).ToList().ForEach(Function(i) Console.WriteLine("{0} : {1}", i.Words, i.WordsRepeated))







Console.ReadKey(True)

End Sub

End Class

End Namespace


Output
----------

hello : Word hello has never repeated

this : Word this has never repeated

is : Word is repeated 3 times

dotnet : Word dotnet repeated 2 times

funda : Word funda has never repeated

Comments or Responses

Login to post response