关闭

Swif学习总结 基本数据类型(一)

标签: Swift
53人阅读 评论(0) 收藏 举报
分类:

let常量与 var变量

var point = (10 , 20)

print(point)


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


print("nihao"+website)


var a = 3

if a == 1{

    print(a)

}



for index in 1...10{

    index

}


for index in 0..<10{

    index

}


let score = 90

switch score{

    

case 0:print("12")

case 1..<60:print("123")

case 90:print("\(score)")

default:

    ()

}


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


switch points{


case (_,2):print("\(points.x), \(points.y)");

    fallthrough

default:

    ()

    

}


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



findasd:for m in 1...300{


    if m == 6{

        break findasd

    }

}



let age = 19


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

    print("you are a teenager and in a college")

}



var strs = "hello world"


for c in strs.characters{

    

//    print(c)

}


let mark:Character = "!"

strs + String(mark)

strs.append(mark)


let enlish:Character = "a"

let chinese:Character = ""

let collguy:Character = "\u{1f60e}"



var str = "Hello, playground"

//str += " ::>"

//print(str)


str.characters.count


let start:String = "hello world"

let startIndex = start.startIndex

//索引后移动6

start[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..<spaceIndex]

let range = startIndexstr..<spaceIndex.predecessor()


str.replaceRange(range, with: "Hi")

str.appendContentsOf("!!!")

str.insert("g", atIndex: str.endIndex)

str.removeAtIndex(str.endIndex.predecessor())

str


str.removeRange(str.endIndex.advancedBy(-2)..<str.endIndex)

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截取的长度6

s3.substringWithRange(NSMakeRange(3, 6))


let s4 = "

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3442次
    • 积分:293
    • 等级:
    • 排名:千里之外
    • 原创:27篇
    • 转载:3篇
    • 译文:0篇
    • 评论:0条