How can I write text in multi-lines in Swift?

uitextfield multiline programmatically in swift swift multi-line string with variables swift multi-line string without newlines multiline textfield swift github swift multi-line string with variables



Basically Swift strings use double quotes, but you can’t include line breaks in there. like this-


let singleLineString = "These are the same."

OUTPUT-

"These are the same."


If you want multi-line strings you need slightly different syntax: start and end with three double quote marks, like this-

let multilineString = """
These are the same.
but its not show space.
"""

OUTPUT-

"These are the same.\nbut its not show space."

If you only want multi-line strings to format your code neatly, and you don’t want those line breaks to actually be in your string, end each line with a \, like this-

let multilineString2 = """
These are the same. \
but its show space.
"""

OUTPUT-

"These are the same. but its not show space."

Thanks for reading!!

Similar solutions you may also like...


Post a Comment

0 Comments