问答详情
源自:2-4 Swift-元组 Tuples

能给源码吗?

能给源码吗?

提问者:得到的 2015-04-06 20:23

个回答

  • 丿心梦无痕
    2016-06-08 18:14:28

    //换行

    var str = "你好,playground"

    var stra = "你sss好,playground"

    var see = "\(str)\n\(stra)"

    print(see)


    //查找一个字符串在一个字符串中的位置范围

    var stringTest = "andy Wangpeng"

    stringTest.rangeOfString("Wangpeng")

    stringTest.rangeOfString("Wangpeng",options: NSStringCompareOptions.CaseInsensitiveSearch)

    stringTest.startIndex

    stringTest.endIndex


    //查找一个字符串在一个指定区域的位置范围(不常用)

    let startIndex:String.Index = stringTest.startIndex.advancedBy(3);

    let endIndex:String.Index = stringTest.endIndex.advancedBy(-3)

    let strRange = startIndex..<endIndex

    stringTest.rangeOfString("Wangpeng",options: NSStringCompareOptions.CaseInsensitiveSearch,range: strRange)


    //截取字符串

    stringTest.substringWithRange(strRange)


    //插入字符串

    stringTest.insert("!", atIndex: startIndex)


    //删除指定字符串

    stringTest.removeAtIndex(startIndex)

    stringTest

    //替换字符串

    stringTest.stringByReplacingCharactersInRange(strRange, withString: "Hello")


    //字符串可以用format了

    var aa = NSString(format: "sssss%d",22) as String


    let login = (true,"慕课女神")


    let(islog,_) = login


    //元组

    var ConnectState = (ResponseCode:404,_:"success",text:"connect to imooc");


    ConnectState.0


  • default_null
    2015-05-14 15:59:08

    - - 照着屏幕打吧- -