The string is a group of order characters enclosed in double quotes. Swift contains an inbuilt data type String to declare and store the collection of characters.

A string in a swift is a collection of Unicode values.

How to create a String in Swift

There are multiple ways to create a string in Swift.

  • Use String Literal

The string can be created like a normal variable using the var or let keyword and initialized using string literal syntax. These are also called string constant literals.

var name="John";
print (name)
  • using String constructor

Swift provides a string constructor that accepts a string value.

var  name1=String("Mark");
print (name1)
  • using multiline string syntax multi-line strings are created using strings that span in multiple lines enclosed in three double quotation marks.
import Foundation
var  multiLineString="""
This is multi line string example
print (multiLineString)