Remove characters from NSString?

后端 未结 6 2148
伪装坚强ぢ
伪装坚强ぢ 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:16

    You can try this

    - (NSString *)stripRemoveSpaceFrom:(NSString *)str {
        while ([str rangeOfString:@"  "].location != NSNotFound) {
            str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
        }
        return str;
    }
    

    Hope this will help you out.

提交回复
热议问题