3. 문자와 문자열 Strings and Characters Swift 공식 문서 - 판나의 노트

3327 단어
//: Playground - noun: a place where people can play

import UIKit

// #       
//         ,  String  。String         ,        。
let quotation = """
The White Rabbit put on his spectacles.  "Where shall I begin,
please your Majesty?" he asked.

"Begin at the beginning," the King said gravely, "and go on
till you come to the end; then stop."
"""
//             ,             ,           。             。
let threeDoubleQuotes = """
    Escaping the first quote \"""

        Escaping all three quotes \"\"\"

    """
print(threeDoubleQuotes)

// #          
// trick:       
var emptyString = ""
if emptyString.isEmpty {
    print("Nothing to see here")
}

// #       

// #        
// trick:        , c   a、b a、b     
var a = "wanna"
var b = "gonna"
var c = [a, b]

// #     
// for-in loop
for character in "Dog!" {
    print(character)
}
//         ,           
let exclamationMark: Character = "!"
// String        Character                     ,    String    init
let catCharacters: [Character] = ["C", "a", "t", "!", ""]
let catString = String(catCharacters)

// #         
var welcome = ""
welcome += "Bonjour"
welcome.append(exclamationMark)

// #      

// # Unicode
// Unicode              、            。     Unicode         
//               
"\0"//    
"\\"//    
"\t"//      
"
"// ,n newline "\r"// ,r return, mac ??? "\""// "\'"// print("hao\rde") "\u{1F443}" // Unicode // let precomposed: Character = "\u{D55C}" // 한 let decomposed: Character = "\u{1112}\u{1161}\u{11AB}" // ᄒ, ᅡ, ᆫ let enclosedEAcute: Character = "\u{E9}\u{20DD}" // // Unicode Character let regionalIndicatorForUS: Character = "\u{1F1FA}\u{1F1F8}" // # // .count Unicode , Unicode var word = "cafe" word.count word += "\u{301}" // combined word.count // # // String [Character], , index。 , // endIndex String , . String , startIndex endIndex 。 var greeting = "Bonjour!" greeting[greeting.startIndex] greeting[greeting.index(after: greeting.startIndex)] greeting[greeting.index(before: greeting.endIndex)] // offsetBy greeting[greeting.index(greeting.startIndex, offsetBy: 1)] // .indices index( endIndex) for index in greeting.indices { print("\(greeting[index])", terminator: "") } // Indexable startIndex endIndex index(before:) , index(after:) index(_:offsetBy:) 。 String , Array , Dictionary Set 。 var test = [1, 2, 3] test[test.startIndex] test[0] // ,remove(at:) Character greeting.remove(at: greeting.index(before: greeting.endIndex)) greeting.removeSubrange(greeting.startIndex..

좋은 웹페이지 즐겨찾기