Remove all whitespaces from NSString

后端 未结 11 1836
北荒
北荒 2020-12-04 06:23

I\'ve been trying to get rid of the white spaces in an NSString, but none of the methods I\'ve tried worked.

I have \"this is a test\" and

11条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 07:25

    This may help you if you are experiencing \u00a0 in stead of (whitespace). I had this problem when I was trying to extract Device Contact Phone Numbers. I needed to modify the phoneNumber string so it has no whitespace in it.

    NSString* yourString = [yourString stringByReplacingOccurrencesOfString:@"\u00a0" withString:@""];
    

    When yourString was the current phone number.

提交回复
热议问题