While row indexes are not random access and are not numbers, you can increase their number to access the nth character:
var s = "Hello, I must be going" s.removeAtIndex(advance(s.startIndex, 5)) println(s)
Of course, you should always check that the string is at least 5 long before doing this!
edit: as @MartinR points out, you can use the forward-index option to advance to avoid the risk of getting past the end:
let index = advance(s.startIndex, 5, s.endIndex) if index != s.endIndex { s.removeAtIndex(index) }
As always, options are your friend:
// find returns index of first match, // as an optional with nil for no match if let idx = s.characters.index(of:",") { // this will only be executed if non-nil, // idx will be the unwrapped result of find s.removeAtIndex(idx) }
source share