The problem is that you read characters from phrase that not exist when phrase is shorter than 25 chars.
I guess you want to remove all the whitespace from the input and store it in newString.
Thank you for your reply.
Would there be another way with out using loop?
Also could you explain what you mean by whitespace from the input? I could not find any.
Please DON'T delete your code after you've got the answer to your question. It makes this thread useless as a learning resource for others. It's a selfish abuse of this forum.
Please edit your OP to restore it with the original code.