Swift--Define an empty string Hasprefix hassuffix trim split join range

Source: Internet
Author: User

Define an empty string

var str1 = ""

var str2 = String ()

Str1.isempty//Judging if the string is empty

All characters in the output string

var str3 = "As God name"

For C in str3{

println (c)

}

Maximum value of type int.max//int

Minimum value of type int.min//int

var arr1 = ["C", "OC", "ios", "Swift"]

var count = 0

For name in arr1{

If Name.hasprefix ("I") {//Hasprefix prefix

count++

Count

}

}

Count = 0

For name in arr1{

If Name.hassuffix ("s") {//Hassuffix suffix

count++

Count

}

}

var string1:string = "Hello, swift!!"

var string2 = "As God name"

Uppercasestring lowercasestring

String2.uppercasestring

String2.lowercasestring

Trim removes whitespace before and after a string

String1.stringbytrimmingcharactersinset (Nscharacterset.whitespaceandnewlinecharacterset ())

String1.stringbytrimmingcharactersinset (Nscharacterset (charactersinstring: "H"))

Split

String2.componentsseparatedbystring ("")

var string3 = "Welcome to play swift! Step-by-Step learn from Now "

String3.componentsseparatedbycharactersinset (Nscharacterset (charactersinstring: "-"))

Join

var String4 = "-"

String4.join (["One", "one", "one", "three"])

var string5 = "--"

var arr = ["ios", "Swift", "OC"]

String5.join (arr)

var str = "Welcome to play swift! Step by step Learn Swift language

Range

Str.rangeofstring ("Step")

Str.rangeofstring ("Step", Options:NSStringCompareOptions.BackwardsSearch)

Str.rangeofstring ("Welcome", Options:NSStringCompareOptions.CaseInsensitiveSearch)

Str.startindex

Str.endindex

Countelements (str)

var str = "Hello, playground"

Let Strrange = range<string.index> (Start:str.startIndex, End:str.endIndex)

Swift--Define an empty string Hasprefix hassuffix trim split join range

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.