user748001
user748001

Reputation: 181

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.

Upvotes: 3

Views: 6654

Answers (4)

Chris Alan
Chris Alan

Reputation: 1426

For remove empty spaces, please use below code,

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

Upvotes: 0

Dileep Reghu
Dileep Reghu

Reputation: 879

NSString *str = @"hel lo";

[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

Upvotes: 1

jigneshbrahmkhatri
jigneshbrahmkhatri

Reputation: 3637

To remove empty space:

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

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

textview.dataDetectorTypes = UIDataDetectorTypeAll;

Upvotes: 9

Eiko
Eiko

Reputation: 25632

NSString *cleanString = [dirtyString stringByReplacingOccurrencesOfString:@"http: //" withString:@"http://"];

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

Upvotes: 1

Related Questions