Swift string interpolation

Source: Internet
Author: User

1 string interpolation is a new way to build a string that contains constants, variables, literals, and expressions. Each entry of the string literal that you insert is wrapped in parentheses prefixed with a backslash:2Let multiplier =33Let message ="\ (multiplier) times 2.5 is \ (Double (multiplier) * 2.5)"4 //message is ' 3 times 2.5 is 7.5 '5 In The example above, multiplier as \ (multiplier) is inserted into a string literal. When you create a string to perform an interpolation calculation, this placeholder is replaced with the multiplier actual value. 6 7The value of multiplier also acts as part of the subsequent expression in the string. The expression evaluates to Double (multiplier) *2.5Value and the result (7.5) into the string. In this example, the expression is written as \ (Double (multiplier) *2.5) and is included in the string literal. 8Note: An expression written in parentheses in your interpolated string cannot contain non-escaped double quotation marks (") and a backslash (\), and cannot contain carriage returns or line feeds. 

Swift string interpolation

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.