Remove all whitespaces from NSString

后端 未结 11 1806
北荒
北荒 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:09

    That is for removing any space that is when you getting text from any text field but if you want to remove space between string you can use

    xyz =[xyz.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    

    It will replace empty space with no space and empty field is taken care of by below method:

    searchbar.text=[searchbar.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];
    

提交回复
热议问题