Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove http:// from NSString

How do I remove certain text from a NSString such as "http://"? It needs to be exactly in that order. Thanks for your help!

Here is the code I am using, however the http:// is not removed. Instead it appears http://http://www.example.com. What should I do? Thanks!

NSString *urlAddress = addressBar.text;
[urlAddress stringByReplacingOccurrencesOfString:@"http://" withString:@""];
urlAddress = [NSString stringWithFormat:@"http://%@", addressBar.text];
NSLog(@"The user requested this host name: %@", urlAddress);
like image 603
Jack Humphries Avatar asked Aug 25 '11 04:08

Jack Humphries


1 Answers

Like this?

NSString* stringWithoutHttp = [someString stringByReplacingOccurrencesOfString:@"http://" withString:@""];

(if you want to remove text at the beginning only, do what jtbandes says - the code above will replace occurrences in the middle of the string as well)

like image 147
SVD Avatar answered Oct 20 '22 21:10

SVD