简介 目录 评价 推荐
  • sunnyyoung91 2018-03-31

    本节String字符串常用方法: var str = "Hello,Swift",swift采用.函数返回对应的索引

    1. let startIndex = str.startIndex,起始索引的字符

    2. let endIndex = str.endIndex,结束索引的字符

    3. 注意的是:字符串的索引范围[startIndex,endIndex)---前闭后开

    4. str[startIndex]    [传入索引]

    5. indexNew = startIndex.advancedBy(5),距离当前索引的第几个索引

    6. str[indexNew]相当于索引6

    7. str[indexNew.predecessor( )]前一个索引的字符,str[indexNew.successor( )]后一个所以的字符

    8. 显示一个str的索引范围内的字符,类subString(a,b),如str[startIndex..<endIndex],采用..<

    9. 类似上面第8点:str.replaceRange(startIndex..<endIndex,with:"Hi")

    10. str.appendContentsOf("!!!"),在末尾添加

    11. str.insert("?",atIndex:str.endIndex)    (插入的内容,插入的位置)

    12. str.removeAtIndex(传入具体的索引),删除指定索引的字符

    13. str.removeRange(str.endIndex.advancedBy(-2)..<endIndex),传入索引的范围,其中:advancedBy(可以是负数),表示在此索引位置之前的某个位置

    0赞 · 0采集
  • 后知后觉老着急了 2018-01-25
    string
    截图
    0赞 · 0采集
  • 后知后觉老着急了 2018-01-25
    String操作
    截图
    0赞 · 0采集
  • qq_未来会来_04328457 2017-12-28
    Stirng的增删改查
    截图
    0赞 · 0采集
  • 慕田峪3354428 2017-12-28
    string的学习
    0赞 · 0采集
  • 我是噩梦 2017-06-25
    predecess前一个 successor后一个
    0赞 · 0采集
  • qq_野_7 2017-06-13
    StartIndex 和endindex构成了一个前闭后开的区间[startindex,endindex),所以字符串最后一个字母的索引是endinex-1
    截图
    0赞 · 0采集
  • jianshelu 2017-03-03
    startIndex advanceby preprocesser end
    截图
    0赞 · 0采集
  • jianshelu 2017-03-03
    不能使用[]获取字符,需要使用index
    截图
    0赞 · 0采集
  • hdadan 2017-02-26
    两个索引之间使用区间运算符连接获得的新的类型的变量range range<index>,<>为泛型
    截图
    0赞 · 0采集
  • hdadan 2017-02-26
    startIndex.advancedBy(n:Int) 可选择字符串中的字符位置并输出 Index.predecessor()当前索引的前一个值 Index.successor() 当前索引的下一个值
    截图
    0赞 · 0采集
  • hdadan 2017-02-26
    不同的unicode符长度不同,因此对于字符串string不能用[n]获取其中字符,characters[n]也不行。 String.Index索引字符串中的字符。 s.starIndex指向开始; s.endIndex指向末尾后一位。
    0赞 · 0采集
  • cjt0226 2017-02-06
    String 使用startIndex作为索引
    截图
    0赞 · 0采集
  • weibo_带你躺赢带你飞_03878026 2016-09-08
    这章掌握的不好,没仔细听
    0赞 · 0采集
  • 布边的天空 2016-08-29
    String字符串的操作
    截图
    0赞 · 0采集
  • 豆伯特 2016-08-02
    successor():获得后一个字符的索引
    0赞 · 0采集
  • 豆伯特 2016-08-02
    变量Index的方法:predecessor(),获得当前字符的前一个字符索引
    0赞 · 0采集
  • 豆伯特 2016-08-02
    Index变量中advancedBy方法:str[startIndex.advancedBy(5)],找到索引为5的字符
    0赞 · 0采集
  • 豆伯特 2016-08-02
    String:Index类型,str.startIndex表示第一个索引
    0赞 · 0采集
  • 口口大爷 2016-07-26
    替换添加插入删除
    截图
    0赞 · 0采集
  • 口口大爷 2016-07-26
    查看索引
    截图
    0赞 · 0采集
  • 尛酒窝3632449 2016-07-16
    spaceIndex.successor() 当前索引的下一个值
    截图
    0赞 · 0采集
  • 尛酒窝3632449 2016-07-16
    spaceIndex.predecessor()当前索引的前一个值
    截图
    0赞 · 0采集
  • 尛酒窝3632449 2016-07-16
    startIndex.advancedBy(n:Int) 可选择字符串中的位置并输出
    截图
    0赞 · 0采集
  • YumaiCode 2016-07-12
    5-3 String.Index 和 Range2
    截图
    0赞 · 0采集
  • YumaiCode 2016-07-12
    5-3 String.Index 和 Range1
    截图
    0赞 · 0采集
  • YumaiCode 2016-07-12
    5-3 String.Index 和 Range
    截图
    0赞 · 0采集
  • 慕丝7178087 2016-06-23
    字符串索引:startIndex<br> endIndex<br> ex:<br> var str="hello,swift"<br> let sIndex=str.startIndex<br> let eIndex=str.endIndex str[sIndex] 输出:第0位置的字符 h<br> str[sIndex.advancedBy(5)] 输出:第从0到5的位置的字符 , str[sIndex.successor()] 输出:sIndex后一位字符 e str[eIndex.predecessor()] 输出:eIndex前一位字符 t //eIndex 返回的是字符最后一位加一的位置
    截图
    0赞 · 0采集
  • PERRY3307877 2016-05-05
    String Index & Range
    截图
    0赞 · 0采集
  • 阿柒的染坊 2016-05-02
    String endIndex是在String之后的一个位置,String的区间[startIndex,endIndex)
    0赞 · 0采集
数据加载中...
开始学习 免费