import UIKit//swift 字符串//1>swift中的字符串String是一个结构体,性能更高//2>NSString是一个OC对象,性能略差//3>String支持直接遍历//4>Swift提供了String和NSString的无缝转换let str = "hello world"//遍历字符串for c in str.characters{ PRint(c)}//字符串拼接//两个字符串之间的拼接let str1 = "你好"let str2 = "世界"let str3 = str1 + str2//字符串和其它标识符的拼接let name = "ZYF"let age = 18let height = 1.88let info = "my name is /(name) , my age is /(age) , my height is /(height)"//拼接字符串时,字符串的格式化let minent = 2let seconds = 8let timeString = String(format: "%02d:%02d", arguments:[minent,seconds])print(timeString)//字符串的截取let urlStr = "www.zhengyanfeng.com"//将String类型转换为NSString类型let header = (urlStr as NSString).substring(to: 3)let body = (urlStr as NSString).substring(with: NSRange(location: 4, length: 12))let afterbody = (urlStr as NSString).substring(from: 17)
新闻热点
疑难解答