Swift - Data Type String Interpolation

Introduction

In Swift, you can use the \() syntax to do string interpolation .

It has the following format:

"Your string literal \(variable_name )"

The following example shows how:

Demo

let myName = "hi"
var strName = "My name is \(myName)"
print(strName)

Result

You can use this method to include a Double value in your string as shown here:

Demo

let radius = 3.45
var circumference = 2 * 3.14 * radius
var strResult = "The circumference is \(circumference)"
print(strResult)//from  ww  w .j  a v a 2  s . com

Result

Related Topics