swift的string学习

tech2023-11-03  100

import Cocoa var someInts:[Int] = [10, 20, 30] for index in someInts { print( "index 的值为 \(index)") } for index in 2...10 { print("\(index) 乘于 5 为:\(index * 5)") } // 使用字符串字面量 var stringA = "Hello, World!" print( stringA ) // String 实例化 var stringB = String("Hello, World!") print( stringB ) // 使用字符串字面量创建空字符串 var stringA1 = "" if stringA1.isEmpty { print( "stringA1 是空的" ) } else { print( "stringA1 不是空的" ) } // 实例化 String 类来创建空字符串 let stringB1 = String() if stringB1.isEmpty { print( "stringB1 是空的" ) } else { print( "stringB1 不是空的" ) } let char1: Character = "A" let char2: Character = "B" print("char1 的值为 \(char1)") print("char2 的值为 \(char2)") for ch in "Runoob" { print(ch) } var varA:String = "Hello " let varB:Character = "G" varA.append( varB ) print("varC = \(varA)") var someInts1 = [Int](repeating: 10, count: 3) var someVar = someInts1[0] print( "第一个元素的值 \(someVar)" ) print( "第二个元素的值 \(someInts1[1])" ) print( "第三个元素的值 \(someInts1[2])" ) var someStrs = [String]() someStrs.append("Apple") someStrs.append("Amazon") someStrs.append("Runoob") someStrs += ["Google"] for item in someStrs { print(item) } var intsA = [Int](repeating: 2, count:2) var intsB = [Int](repeating: 1, count:3) var intsC = intsA + intsB for item in intsC { print(item) } print("intsA.isEmpty = \(intsA.isEmpty)") print("intsB.isEmpty = \(intsB.isEmpty)") print("intsC.isEmpty = \(intsC.isEmpty)")

 

最新回复(0)