Swift Program to Compare Two Strings Using Equal to (==) Operator

You are currently viewing Swift Program to Compare Two Strings Using Equal to (==) Operator

Swift program to compare two strings using equal to (==) operator

// Swift program to compare two strings 
// using equal to (==) operator

var str1 = "Hello World";
var str2 = "Hello World";
var str3 = "Hiii";

if(str1==str2)
{
    print("str1 and str2 are equal");
}
else
{
    print("str1 and str2 are not equal");
}
if(str1==str3)
{
    print("str1 and str3 are equal");
}
else
{
    print("str1 and str3 are not equal");
}

Output

str1 and str2 are equal
str1 and str3 are not equal

...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