How do I concatenate strings in Swift?

前端 未结 20 1730
梦毁少年i
梦毁少年i 2020-11-28 03:04

How to concatenate string in Swift?

In Objective-C we do like

NSString *string = @\"Swift\";
NSString *resultStr = [string stringByAppen         


        
相关标签:
20条回答
  • 2020-11-28 04:07

    It is called as String Interpolation. It is way of creating NEW string with CONSTANTS, VARIABLE, LITERALS and EXPRESSIONS. for examples:

          let price = 3
          let staringValue = "The price of \(price) mangoes is equal to \(price*price) "
    

    also

    let string1 = "anil"
    let string2 = "gupta"
    let fullName = string1 + string2  // fullName is equal to "anilgupta"
    or 
    let fullName = "\(string1)\(string2)" // fullName is equal to "anilgupta"
    

    it also mean as concatenating string values.

    Hope this helps you.

    0 讨论(0)
  • 2020-11-28 04:08
    var language = "Swift" 
    var resultStr = "\(language) is a new programming language"
    
    0 讨论(0)
提交回复
热议问题