I have a depressing feeling you're using the String class rather than dealing with character arrays directly. If you are using String, I suggest you think about getting rid of it. Either way, it'll be difficult to guess why your sketch is going wrong until you post a complete sketch that demonstrates the problem.