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,955 questions

51,897 answers

573 users

How to find the second largest word in a string with VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Function FindSecondLargestWordInString(ByVal s As String) As String
        Dim words As String() = s.Split(" "c)
		
        Array.Sort(words, Function(a, b) b.Length.CompareTo(a.Length))

        If words.Length > 1 Then
            Return words(1)
        Else
            Return Nothing
        End If
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim s As String = "c cpp cobol c# vb python java"
			
        Dim secondLongest As String = FindSecondLargestWordInString(s)

        If secondLongest IsNot Nothing Then
            Console.WriteLine("The second longest word is: " & secondLongest)
        Else
            Console.WriteLine("No second longest word found.")
        End If
    End Sub
End Class



' run:
'
' The second longest word is: cobol
'


 



answered Jun 2, 2024 by avibootz

Related questions

1 answer 176 views
1 answer 108 views
1 answer 623 views
3 answers 126 views
1 answer 80 views
1 answer 78 views
1 answer 81 views
...