The string of Swift notes _swift

Source: Internet
Author: User


Brief introduction

Strings in string are value types, and when passed, the values are copied, and NSString string passes are references. We can iterate through the string with for:

Copy Code code as follows:

var a:string = "a"
For C in "Hello" {
println (c)

You can calculate the number of characters for a string by countelements:

Copy Code code as follows:

Countelements ("1234567")//7

Note, however, that the length of countelements and nsstring is not always exactly the same value, because length takes advantage of the value of the UTF-16 type, not the Unicode character. For example, after emoji expression added, the result of UTF-16 calculation is 2, and the result of Unicode is 1. You can look at the following example:

Copy Code code as follows:

var a = "Hello

The above mentioned is the entire content of this article, I hope you can enjoy.

Related Article

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: 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.