A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Longest Word in Visual Basic page! Here, you'll find the source code for this program as well as a description of how the program works.
Public Module LongestWord
Public Sub Main(args As String())
' Check if input is provided
If args.Length = 0 Then
Usage()
Exit Sub
End If
' Join the arguments to form the full input string
Dim multi As String = String.Join(" ", args).Trim()
' Replace newlines, carriage returns, and tabs with spaces
multi = multi.Replace(vbCrLf, " ").Replace(vbCr, " ").Replace(vbLf, " ").Replace(vbTab, " ")
' Split the string into words by spaces, removing empty entries
Dim words As String() = multi.Split(" "c, StringSplitOptions.RemoveEmptyEntries)
' If there are no words, print usage
If words.Length = 0 Then
Usage()
Exit Sub
End If
' Find the longest word length
Dim longestWord As String = ""
Dim maxLength As Integer = 0
' Loop through the words and find the longest
For Each word As String In words
If word.Length > maxLength Then
longestWord = word
maxLength = word.Length
End If
Next
' Output the length of the longest word
System.Console.WriteLine(maxLength)
End Sub
Public Sub Usage()
System.Console.WriteLine("Usage: please provide a string")
End Sub
End Module
Longest Word in Visual Basic was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.