Remove characters from NSString?

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

    Taken from NSString

    stringByReplacingOccurrencesOfString:withString:
    

    Returns a new string in which all occurrences of a target string in the receiver are replaced by another given string.

    - (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement
    

    Parameters

    target

    The string to replace.
    

    replacement

    The string with which to replace target.
    

    Return Value

    A new string in which all occurrences of target in the receiver are replaced by replacement.

提交回复
热议问题