Check substring in a string with and without using inbuilt functions