Imports System
Imports System.Linq
Module WordAnalyzer
''' <summary>
''' Finds the largest and smallest words in a given string.
''' </summary>
''' <param name="text">The input string containing words.</param>
''' <returns>A named value tuple containing the largest and smallest words.</returns>
Public Function FindLargestAndSmallestWords(text As String) As (Largest As String, Smallest As String)
If String.IsNullOrWhiteSpace(text) Then
Return (String.Empty, String.Empty)
End If
' Split the string by whitespace characters, discarding empty entries
Dim words As String() = text.Split(New Char() {" "c, environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
If words.Length = 0 Then
Return (String.Empty, String.Empty)
End If
' Use LINQ OrderBy/OrderByDescending to find extrema by length
Dim largest As String = words.OrderByDescending(Function(w) w.Length).First()
Dim smallest As String = words.OrderBy(Function(w) w.Length).First()
Return (largest, smallest)
End Function
Sub Main()
Dim s As String = "Visual Basic is a modern, object-oriented programming language"
' Destructure the named value tuple returned by the function
Dim result = FindLargestAndSmallestWords(s)
Console.WriteLine($"Largest word: {result.Largest}")
Console.WriteLine($"Smallest word: {result.Smallest}")
End Sub
End Module
' run:
'
' Largest word: object-oriented
' Smallest word: a
'