Swift Program To Check A String Is Empty Or Not

You are currently viewing Swift Program To Check A String Is Empty Or Not

Swift Program To Check A String Is Empty Or Not

// Swift program to check a string 
// is empty or not

var str1 = ""
var str2 = String()
var str3 = "Hello World"

if(str1.isEmpty)
{
    print("str1 is an empty string")
}
else
{
    print("str1 is not empty string")
}
if(str2.isEmpty)
{
    print("str2 is an empty string")
}
else
{
    print("str2 is not empty string")
}
if(str3.isEmpty)
{
    print("str3 is an empty string")
}
else
{
    print("str3 is not empty string")
}

Output

str1 is an empty string
str2 is an empty string
str3 is not empty string

...Program finished with exit code 0
Press ENTER to exit console.

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply