In: Computer Science
Description:
To create a Visual Basic program that will obtain a sentence from the user, parse the sentence, and then display a sorted list of the words in the sentence with duplicate words removed.
Tasks:
Submit:
Application Name :WindowsApp_SortedList
Type of Application:Windows Forms Application
Language used :VB
Form1.vb [Design]
******************************************
Form1.vb :
Imports System.Array
Public Class Form1 'VB Form
'Sort Button click
Private Sub btnSort_Click(sender As Object, e As EventArgs) Handles
btnSort.Click
'declaring variable
Dim sentence As String
'declaring arraylist to store unique word
Dim wordsList As New ArrayList()
'take sentence from user
sentence = txtSentence.Text
'converting sentence to array based on space
Dim wordsArray As String() = sentence.Split(" ")
'using VB Array.Sort() method sort the wordsArray
Array.Sort(wordsArray)
'remove duplicate from the array using
'declaring variable to store array elements
Dim words As String = ""
'using for each loop
For Each words In wordsArray
If Not wordsList.Contains(words) Then
'if array list does not contin the given word then
'add that word in the list
wordsList.Add(words)
End If
Next
'using for each loop
For Each words In wordsList
'display sentence on the label
lblResult.Text = lblResult.Text & " " & words
Next
End Sub
End Class
=============================================
Output :