Swif學習總結 基本資料型別(一)

2021-07-22 06:15:02 字數 2094 閱讀 3806

let常量與 var變數

var point = (10 , 20)

print(point)

let website:string = "ww.ic.c"

print("nihao"+website)

var a = 3

if a == 1

for index in 1...10

for index in 0..<10

let score = 90

switch score

let points: (x:int , y:int) = (1, 2)

switch points

let yuanzu: ( x:int , y:int) = (1,23)

findasd:for m in 1...300}

let age = 19

if case 10...19 = age where age >= 18

var strs = "hello world"

for c in strs.characters

let mark:character = "!"

strs + string(mark)

let enlish:character = "a"

let chinese:character = "你"

let collguy:character = "\u"

var str = "hello, playground"

//str += " ::>"

//print(str)

str.characters.count

let start:string = "hello world"

let startindex = start.startindex

//索引後移動

6start[startindex.advancedby(6)]

//輸出前乙個字元

//start[startindex.predecessor()]

//輸出後乙個字元

start[startindex.successor()]

let startindexstr = str.startindex

let spaceindex = startindexstr.advancedby(6)

let endindex = str.endindex

str[endindex.predecessor()]

str[startindexstr..

let range = startindexstr..

str.replacerange(range, with: "hi")

str.insert("g", atindex: str.endindex)

str.removeatindex(str.endindex.predecessor())

str

str.removerange(str.endindex.advancedby(-2)..

str.uppercasestring

str.lowercasestring //

是否包含特定的字元

字首是否相同

字尾是否相同

str.containsstring("hello")

str.hasprefix("he")

str.hassuffix("ft")

let s = "one third is \(1.0/3.0)"

//nsstring

(不是基於

unicode的)與

string

的相互轉化

let s2:string = nsstring(format: "ont third is %.2f", 1.0/3.0) as string

var s3:nsstring = "one third is 0.33"

s3.substringfromindex(4)

s3.substringtoindex(5)

//開始的位置

3擷取的長度

6s3.substringwithrange(nsmakerange(3, 6))

let s4 = "

基本資料型別總結

基本資料型別 型別 型別說明 使用說明 整形integer 標準資料型別,使用前不必定義 實型reall 標準資料型別,使用前不必定義 字元型character 標準資料型別,使用前不必定義 字串型 string 標準資料型別,使用前不必定義 布林型boolean 標準資料型別,使用前不必定義 列舉...

基本資料型別總結

基本資料型別 型別 型別說明 使用說明 整形integer 標準資料型別,使用前不必定義 實型reall 標準資料型別,使用前不必定義 字元型character 標準資料型別,使用前不必定義 字串型 string 標準資料型別,使用前不必定義 布林型boolean 標準資料型別,使用前不必定義 列舉...

基本資料型別總結

一.可變和不可變型別 x 5 id x 140722754799392 x 6 id x 140722754799424 記憶體位址改變了,說明整形是不可變型別,浮點型也一樣 字串型別 str1 大傻子嗎 id str1 2368083743248 str1 臭妹妹呀 id str1 2368083...