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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,227 questions

56,129 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 Feb 11 by avibootz
...