views:

5174

answers:

2

NSString *myString = @"A B C D E F G";

I want to remove the spaces, and get a string out like "ABCDEFG".

Please help me...

Thanks and regards

+13  A: 

You could use:

NSString *stringWithoutSpaces = [myString stringByReplacingOccurencesOfString:@" " withString:@""];
Tom
Please can you format code snippets in a monospaced font for legibility. At present distinguishing the first string is a little tricky
Mike Abdullah
+8  A: 

If you want to support more than one space at a time, or support any whitespace, you can do this:

NSString * noSpaces = [[myString componentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceCharacterSet]] componentsJoinedByString: @""];
Jim Dovey