- Gets the character of a location in the string, the difference between the swift versions
Let text = "abc" Let INDEX2 = Text.index (Text.startindex, offsetby:2)//will call succ 2 timeslet lastchar:character = Te XT[INDEX2]//now we can index!let characterIndex2 = Text.characters.index (Text.characters.startIndex, Offsetby:2) let LASTCHAR2 = Text.characters[characterindex2]//will do the samelet range:range<string.index> = Text.range (of: "B") !let index:int = text.distance (From:text.startIndex, To:range.lowerBound)
Let text = "abc" Let INDEX2 = Text.startIndex.advancedBy (2)//will call succ 2 Timeslet lastchar:character = Text[index2] Now we can index!let Lastchar = text.characters[index2]//will do the samelet range:range<string.index> = Text.ra Ngeofstring ("B")!let Index:int = Text.startIndex.distanceTo (range.startindex)//will call Successor/predecessor Several times until the indices match
Let text = "abc" Let INDEX2 = Advance (Text.startindex, 2)//will call succ 2 Timeslet lastchar:character = Text[index2]// Now we can index!let range = text.rangeofstring ("b") Let Index:int = Distance (Text.startindex, Range.startindex)//will CA ll Succ/pred several times
[Swift] The pit of a string