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.
Asked
Active
Viewed 6,647 times
3
-
possible duplicate of http://stackoverflow.com/questions/925780/remove-character-from-nsstring-in-iphone-programming ? – Prashant Bhate Jul 04 '11 at 09:30
-
Follow the [link](http://borkware.com/quickies/single?id=399). – rptwsthi Jul 04 '11 at 09:08
4 Answers
9
To remove empty space:
str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
Use following to detect site or phone number in text view.
textview.dataDetectorTypes = UIDataDetectorTypeAll;

jigneshbrahmkhatri
- 3,627
- 2
- 21
- 33
1
NSString *cleanString = [dirtyString stringByReplacingOccurrencesOfString:@"http: //" withString:@"http://"];
I'd wonder why you get this odd string in the first place, though.

Eiko
- 25,601
- 15
- 56
- 71
1
NSString *str = @"hel lo";
[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

visakh7
- 26,380
- 8
- 55
- 69

Dileep Reghu
- 879
- 7
- 6
0
For remove empty spaces, please use below code,
str = [str stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

Amar
- 13,202
- 7
- 53
- 71

Chris Alan
- 1,426
- 14
- 14