[Swift learning] Swift programming tour-character and string (5), swift tour

Source: Internet
Author: User

[Swift learning] Swift programming tour-character and string (5), swift tour

String is the String type of swift. A string is a valid Character Sequence. Therefore, a character set can be expressed in combination. You can use the + symbol to connect to a string. String type is a fast and modern String implementation. Each string is composed of Unicode characters of independent encoding and supports accessing these characters in different Unicode representation. Use "" to mark strings.

I. Initialize an empty string

var emptyString = ""    
var anotherEmptyString = String()


The two initialization methods are equivalent.

IsEmptyDetermines whether the current string is a null string.

if emptyString.isEmpty {
    print("Nothing to see here")


The String type of Swift is the value type. If you create a new string value, the value is copied when it is used to assign values to constants or variables, or when it is passed in a function/method. In different cases, a new copy of an existing string value is created, and the new copy is passed or assigned a value.


Ii. Characters usage

You can use the for-in loop to access individual characters of a string.

For character in "Dog!

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