Is there any alternate Solution for given problem?

Problem Link
This is my Solution

I have done it using string. Is there any alternate solution where we can solve it without using a substring function?