7ee Subj : Re: strtrim To : borland.public.cpp.borlandcpp From : maeder Date : Wed Dec 22 2004 07:01 pm "Sebastian Ledesma" writes: > There is a standard funtion to eliminate blank spaces in a string (at start > y/o end). I was looking for it but didn't (I have my code > but i was looking for a official solution). No. The Standard C Library string functions don't dynamically allocate new strings, and this would be necessary for this task. There is strcspn(), though, which you can use to find the number of leading spaces. Add the result to a pointer to the beginning of the string, and you have a pointer to the first non-space character. I don't think that there is anything equivalent for skipping spaces from the back of the string. Alternatively, you can use Standard C++ Library functions on character arrays. E.g.: #include #include #include #include #include #include #include int main() { char const *tobetrimmedstart(" the guts "); char const *tobetrimmedend(tobetrimmedstart+std::strlen(tobetrimmedstart)); char const *trimmedstart(std::find_if(tobetrimmedstart,tobetrimmedend, std::bind2nd(std::not_equal_to(), ' '))); typedef std::reverse_iterator back_it; char const *trimmedend(std::find_if(back_it(tobetrimmedend), back_it(tobetrimmedstart), std::bind2nd(std::not_equal_to(), ' ')) .base()); std::cout << '/' << std::string(trimmedstart,trimmedend) << "/\n"; } Most of this is beyond what old c++ implementations such as Borland C++ support, but depending on which version you use, you might be able to adapt this code to what is supported. . 0