Swift - Split string over multiple lines

前端 未结 15 2034
清酒与你
清酒与你 2020-12-04 07:51

How could I split a string over multiple lines such as below?

var text:String = \"This is some text
                   over multiple lines\"
15条回答
  •  死守一世寂寞
    2020-12-04 08:34

    Swift 4 has addressed this issue by giving Multi line string literal support.To begin string literal add three double quotes marks (”””) and press return key, After pressing return key start writing strings with any variables , line breaks and double quotes just like you would write in notepad or any text editor. To end multi line string literal again write (”””) in new line.

    See Below Example

         let multiLineStringLiteral = """
        This is one of the best feature add in Swift 4
        It let’s you write “Double Quotes” without any escaping
        and new lines without need of “\n”
        """
    
    print(multiLineStringLiteral)
    

提交回复
热议问题