Chapter 03: Let’s Learn Swift Programming Language – String in Swift

All About String in Swift Programming Language

Let’s know what is String, String is collection of characters

Here is how to declare a String

var courseName = "iOS Development"
var language = "Swift"

Here is how to use functions like String Concatenation i.e. attaching one string to second string

var hello = "Hello, "
let world = "World! "
let sentence = hello + world + "This is iOS Development" // "Hello, world! This is iOS Development"


Important Note: As you can see above we have used “+” operator to concatenate two strings together

Here is how to use functions like String Interpolation i.e. A way to write some code in the middle of the string. The returned value of the code will turn into part of the string.

var courseName = "iOS Development"
var language = "Swift"
var software = "Xcode"
var emotionEmoji = " 😍 " // Unicode Character i.e. Emoji Icon
var swiftVersion = 3.0 // Double or Floating point Number


var fact = "\(courseName) in \(language) with \(software) is so fun! \(emotionEmoji) & we are using swift with version \(swiftVersion)" // So it will read as "iOS Development in Swift with Xcode is so fun! 😍 & we are using swift with version 3.0"

String Properties & Call methods using dot notation / operators

Here is how to check if s string is empty

fact.isEmpty // false

Convert all characters of string into upper / lower case


var name = "TheIronMan"
name.lowercased() // It will appear as "theironman"
name.uppercased() // It will appear as "THEIRONMAN"

Here is how we can compare if two string are identical for this we will use the logical equivalent (==) operator

let mySchool = "Harvard"
let yourSchool = "Stanford"


mySchool == yourSchool // false

I hope this blog post will help you to better understand Strings in Swift Programming Language,

Thanks & Regards
Mandar Apte

Leave a Reply

Your email address will not be published. Required fields are marked *