How do I concatenate strings in Swift?

前端 未结 20 1850
梦毁少年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 03:49

    In Swift 5 apple has introduces Raw Strings using # symbols.

    Example:

    print(#"My name is "XXX" and I'm "28"."#)
    let name = "XXX"
    print(#"My name is \#(name)."#)
    

    symbol # is necessary after \. A regular \(name) will be interpreted as characters in the string.

提交回复
热议问题