Remove characters from NSString?

后端 未结 6 2153
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 18:01
NSString *myString = @\"A B C D E F G\";

I want to remove the spaces, so the new string would be \"ABCDEFG\".

6条回答
  •  伪装坚强ぢ
    2020-11-29 18:36

    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:@""];
    

提交回复
热议问题