Swift - Split string over multiple lines

前端 未结 15 2067
清酒与你
清酒与你 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

    Multi-line strings are possible as of Swift 4.0, but there are some rules:

    1. You need to start and end your strings with three double quotes, """.
    2. Your string content should start on its own line.
    3. The terminating """ should also start on its own line.

    Other than that, you're good to go! Here's an example:

    let longString = """
    When you write a string that spans multiple
    lines make sure you start its content on a
    line all of its own, and end it with three
    quotes also on a line of their own.
    Multi-line strings also let you write "quote marks"
    freely inside your strings, which is great!
    """
    

    See what's new in Swift 4 for more information.

提交回复
热议问题