简体   繁体   中英

How to remove empty space from NSString in iPhone

i am getting one url from the server http: / /www.google.com, however due to space in between them it is not opening, please let me know how to remove the space in between them, so that it should open in safari.

To remove empty space:

str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];

Use following to detect site or phone number in text view.

textview.dataDetectorTypes = UIDataDetectorTypeAll;
NSString *cleanString = [dirtyString stringByReplacingOccurrencesOfString:@"http: //" withString:@"http://"];

I'd wonder why you get this odd string in the first place, though.

NSString *str = @"hel lo";

[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

For remove empty spaces, please use below code,

str = [str stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM