HomeiOS Developmentios - ReplacingCharactersInRange out of bounds error

ios – ReplacingCharactersInRange out of bounds error


The vary {8,1} means you are attempting to entry the ninth character. However your if examine solely verifies if the string has 8 or extra characters. So if the string is precisely 8 characters lengthy then you’ll get that error.

Replace your if examine to:

if (self.txtQty.textual content.size > 8) {

Or presumably your if examine is right and the vary ought to be modified from {8,1}, to {7,1} to exchange the eighth character.

Which of these two adjustments you make will depend on your objective (to vary the eighth or ninth character).


To assist visualize the vary, I will try a little bit of a drawing:

Some string, its indexes, and vary {8,1}:

 1 2 3 4 5 6 7 8 9 0   <-- The string
| | | | | | | | | | |
0 1 2 3 4 5 6 7 8 9 1  <-- Its indexes
                    0
                ***    <-- Space for {8,1}

Right here you’ll be able to see that the vary {8,1} is getting the ninth character.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments