Swift-string, Character

Source: Internet
Author: User

String, Character

String uses double quotation marks (") as the bounds in Swift:

"Hello!"  // greeting‘stypeisString

Character can be initialized from string, as long as it contains only one character:

let"H"// validlet"??"// validlet"abc"// invalid - multiple grapheme clusters
String insertion Value

String interpolation allows an expression to be injected, which can be any value, including strings, integers, floating-point numbers, and other kinds.

The syntax is a slash, followed by a pair of parentheses around the value: \(value) . Any valid expression can appear in parentheses, including function calls.

let number = 5let interpolatedNumber = "\(number)" // string is "5"let fortyTwo = "\(6 * 7)" // string is "42"let example = "This post has \(number) view\(number == 1 ? "" : "s")"// It will output "This post has 5 views" for the above example.// If the variable number had the value 1, it would output "This post has 1 view" instead.
Special characters
    • /
      Null character
    • \
      Slash Slash
    • \ t
      tab character
    • \v
      Portrait tab
    • \ r
      Carriage return character
    • \ n
      Line break
    • \”
      Double quotes
    • \’
      Single quotation marks
    • \u{n}
      Unicode symbols

Like what:

message"Then he said, \"I \u{1F496} you!\""print(message"I ?? you!"

Swift-string, Character

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.