I am using Swift 3 and have a long string containing 0's and 1's.
Ex. "1111001111111111001111111111000111000000000111000111111111100000000111100111100111111111100000000011100011111111110011110011110000000000000000000"
I am trying to split up this string into two arrays, to determine how many 1's and 0's are repeating after another.
When I call the method let oneArray = binString.components(separatedBy: "0") and let zeroArray = binString.components(separatedBy: "1") The returned arrays we get for our example string is:
["1111", "", "1111111111", "", "1111111111", "", "", "111", "", "", "", "", "", "", "", "", "111", "", "", "1111111111", "", "", "", "", "", "", "", "1111", "", "1111", "", "1111111111", "", "", "", "", "", "", "", "", "111", "", "", "1111111111", "", "1111", "", "1111", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]
["", "", "", "", "00", "", "", "", "", "", "", "", "", "", "00", "", "", "", "", "", "", "", "", "", "000", "", "", "000000000", "", "", "000", "", "", "", "", "", "", "", "", "", "00000000", "", "", "", "00", "", "", "", "00", "", "", "", "", "", "", "", "", "", "000000000", "", "", "000", "", "", "", "", "", "", "", "", "", "00", "", "", "", "00", "", "", "", "0000000000000000000"]
And we don't understand why we can't just return arrays with just the 0's and 1's and not the empty strings as array elements. It doesn't seem that anyone else has asked this kind of question before, and we are confused because this seems to be the general method used to delimit strings from a character.
I'm wondering how to separate these strings the way we want. Seems like a weird situation here