Trim and TrimEnd support.

I Implemented the finding of the indexes so to minimize the malloc() operations that will be performed.