Stripping blank spaces and newlines from strings in C
        Posted  
        
            by Nazgulled
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Nazgulled
        
        
        
        Published on 2010-03-27T00:42:24Z
        Indexed on 
            2010/03/27
            0:43 UTC
        
        
        Read the original article
        Hit count: 549
        
Hi,
I have some input like this:
"  aaaaa      bbb \n cccccc\n ddddd \neeee   "
And I need to sanitize it like this:
"aaaaa bbb cccccc ddddd neeee"
Basically:
- Trim all blank spaces at the beginning and end of the string
- Strip all new lines
- Strip all spaces when there is more than one, but always leave ONE space between words
Is there any easy way to do this or I'll have to process the string, char by char and copy the appropriate chars to a different variable?
© Stack Overflow or respective owner