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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to find the shortest string in array of strings in VB.NET

3 Answers

0 votes
Imports System
				
Public Module Module1
	Public Sub Main()
		Dim arr() As String = {"c++", "python", "c#", "java"}
		Dim shortest_string As String = arr(0)
		
		For Each s As String In arr
  			If s.Length < shortest_string.Length Then
    			shortest_string = s
  			End If
		Next
		
		Console.Write(shortest_string)
	End Sub
End Module



' run:
'  
' c#
'  

 





answered Mar 7, 2021 by avibootz
edited Mar 7, 2021 by avibootz
0 votes
Imports System
                 
Public Module Module1
    Public Sub Main()
        Dim arr() As String = {"c++", "python", "c#", "java"}
		Dim shortest_string As String = arr(0)
 
        For Each s in arr
            If Not String.IsNullOrEmpty(s) AndAlso s.Length < shortest_string.Length Then
                shortest_string = s
            End If       
        Next
         
        Console.Write(shortest_string)
    End Sub
End Module
 
 
 
' run:
'  
' c#
'

 





answered Mar 7, 2021 by avibootz
0 votes
Imports System
Imports System.Linq

Public Module Module1
    Public Sub Main()
        Dim arr() As String = {"c++", "python", "c#", "java"}

		Dim shortest_string As String = arr.OrderByDescending(Function(s) s.Length).LastOrDefault()
         
        Console.Write(shortest_string)
    End Sub
End Module
 
 
	
 
' run:
'  
' c#
'  

 





answered Mar 7, 2021 by avibootz

Related questions

2 answers 84 views
2 answers 93 views
3 answers 159 views
...