Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to find the length of the shortest word in a string with VB.NET

1 Answer

0 votes
Imports System
Imports System.Linq

Module Program

    Function ShortestWordLength(text As String) As Integer
        ' Split on whitespace; RemoveEmptyEntries avoids empty strings
		Dim words() As String = text.Split({" "c, Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)

        If words.Length = 0 Then
            Return 0
        End If

        ' LINQ-like approach using Enumerable.Min
        Dim minLen As Integer = words.Min(Function(w) w.Length)
        Return minLen
    End Function


    Sub Main()
        Dim input As String = "Find the shortest word length in this string"
        Dim result As Integer = ShortestWordLength(input)

        If result = 0 Then
            Console.WriteLine("No words found.")
        Else
            Console.WriteLine("Length of the shortest word: " & result)
        End If
    End Sub

End Module



' run:
'
'  Length of the shortest word: 2
'

 



answered 1 day ago by avibootz
...