I need to check if the index number of a string is divisible by 2.
Here is what I need to do:
I have a string 0BCB7A0D87AD101B500B I need to remove all "0" characters from the string, but only if they are at an odd number in the string. I need to break it down as follows
0B|CB|7A|0D|87|AD|10|1B|50|0B
and only remove the "0" if it is the first character in the pair.
B|CB|7A|D|87|AD|10|1B|50|B
Then put the string back together
BCB7AD87AD101B50B
This code doesn't work, but this is how I am looking at doing it. I'm breaking up the string into an array:
var characters = Array("0BCB7A0D87AD101B500B")
for letter in characters {
if characters(index: Int) % 2 != 0 { // if index has a remainder after being divided by 2
if letter == "0"{
characters.removeAtIndex(index: Int)
}
}
}
I just can't divide or get the index number of the letter/string in the array.
