you do the sub-string conversion in your for loop:
to get the result.
you are converting the whole string back to an integer after casting it to a string, not the sub-string.
That is indeed a mistake of me, that should be result:
You defined a beautiful variable called result, which i assume has as purpose to store the result?