Swift characters in strings

Source: Internet
Author: User

What are the string and Character Types of Swift ?? Provides a fast and Unicode-compatible way to process code.

String constant

let strTest = "I‘m Swift"

String null value judgment

let  emptyString = ""if emptyString.isEmpty {2. println("Nothing to see here")3. }

String variability. The variability of the string is determined by VAR or let. VaR indicates variable strings, and let indicates constant strings.

var strMsg = "test message"strMsg = "reset message"let strConst = "msg const"

String concatenation string supports the plus (+) and minus (+ =) operations.

var strMsg = "msg "let strConst = "const "strMsg = strMsg + strConststrMsg += "endl"println("\(strMsg)")

String is a collection of single Unicode characters character

For char in "TST ** Han" {println ("\ (char) \ n ")}

Number of string characters. Use the countelements Function

VaR strtest = "C plug is te" println ("\ (countelements (strtest ))")

String comparison provides three methods to compare string values: equal strings, equal prefixes, and equal suffixes. String =

Hasprefix/hassuffix method to check whether the string has a specific prefix/suffix

VaR strtest = "C plug is te" Var strsecond = "C plug is te" If strtest = strsecond {println ("same");} If strtest. hassuffix ("te") {println ("has SUF ");}

String case-sensitive version

Returned by uppercasestring and lowercasestring of the string

 

Let normal = "Hello, Ketty! Hello "Var shouty = normal. uppercasestringvar whispered = normal. lowercasestringprintln (" \ (shouty) \ n \ (Whispered) ") // output hello, Ketty! Hello, Ketty! Hi!

 

Character Type Declaration

Let chtest: character = "" // here is double quotation marks.

 

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.