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

51,935 answers

573 users

How to check if a string is blank (empty, nothing, or contains only whitespace) in VB.NET

1 Answer

0 votes
Imports System

Class IsBlankOrEmpty
    Public Shared Function IsBlankOrEmptyMethod(ByVal str As String) As Boolean
        If String.IsNullOrEmpty(str) Then
            Return True
        End If

        For Each ch As Char In str

            If Not Char.IsWhiteSpace(ch) Then
                Return False
            End If
        Next

        Return True
    End Function

    Public Shared Sub Main()
        Dim test1 As String = Nothing
        Dim test2 As String = ""
        Dim test3 As String = "   "
        Dim test4 As String = "abc"
	
        Console.WriteLine("Test1: " & IsBlankOrEmptyMethod(test1))
        Console.WriteLine("Test2: " & IsBlankOrEmptyMethod(test2))
        Console.WriteLine("Test3: " & IsBlankOrEmptyMethod(test3))
        Console.WriteLine("Test4: " & IsBlankOrEmptyMethod(test4))
    End Sub
End Class



' run:
'
' Test1: True
' Test2: True
' Test3: True
' Test4: False
'

 



answered Jun 7, 2025 by avibootz
...