As the code comment says, if the string is an even length then the middle of the String is two characters:
The middle would be 34.
For an odd length the middle is a single character:
1234567 gives 4.
So the if statement has determined whether the String is even or odd, and set the value of position to the first character of the 'middle', and the length of the middle.
So position of 123456 would be 2, which represents the number 3 in the String as positions are 0-based, with a length of 2.
For 1234567 you would have a position of 3 (it's int division, so the 0.5 is lost), which is the position of the 4, with a length of 1.
posted 1 week ago
right Dave, I wrote those comments and just needed to check if i was right, thanks!
My pie came with a little toothpic holding up this tiny ad: