Write a VB.net program to find the find a particular string among the comma seperated strings

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

Namespace ConsoleApplication3
Class Program
Private Shared Sub Main(args As String())
Dim objCar As New List(Of Car)()
objCar.Add(New Car() With { _
Key .ID = 1, _
Key .CarNames = "Finch,Pellandini,Kremer,Studebaker" _
})
objCar.Add(New Car() With { _
Key .ID = 2, _
Key .CarNames = "Theologou,Premier,REVA,Chinkara,Ferrari" _
})
objCar.Add(New Car() With { _
Key .ID = 3, _
Key .CarNames = "Porsche,Mercedes Benz" _
})
objCar.Add(New Car() With { _
Key .ID = 4, _
Key .CarNames = "Volkswagen,Audi,Finch,BMW" _
})
objCar.Add(New Car() With { _
Key .ID = 5, _
Key .CarNames = "Lamborghini,Fiat,Maserati,Honda" _
})
objCar.Add(New Car() With { _
Key .ID = 6, _
Key .CarNames = "Proton,Finch,Tan Chong Motor,VAM" _
})

Dim searchString As String = "Finch"
Dim stringSeparator As String() = New String() {","}

objCar.ForEach(Function(i)
If i.CarNames.Split(stringSeparator, StringSplitOptions.None).Any(Function(j) j.StartsWith(searchString)) Then
Console.WriteLine("The search string {0} is present in {1} where the ID is {2}", searchString, i.CarNames, i.ID)
End If

End Function)
Console.ReadKey()
End Sub
End Class

Public Class Car
Public Property ID() As Integer
Get
Return m_ID
End Get
Set
m_ID = Value
End Set
End Property
Private m_ID As Integer
Public Property CarNames() As String
Get
Return m_CarNames
End Get
Set
m_CarNames = Value
End Set
End Property
Private m_CarNames As String
End Class
End Namespace

Comments or Responses

Login to post response