2

I'm creating a simple web browser as an exercise.

-(IBAction)go:(id)sender {
NSString *query = [_urlField.text stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@",query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
}

I would like it to know how I could add a UIActivityIndicator while loading my webView.

2nd question:

Is it possible to remove the http:// if the user enters it? I know you can do this in PHP like this:

if(strpos($URL, "http://") !== false)

How could I use it in Objective C?

Thanks you all for helping me.

3
  • Please in the future, separate your questions. Commented Nov 17, 2012 at 18:26
  • I'm sorry. I'm new here. I'll do it in the future. Commented Nov 17, 2012 at 18:28
  • No problem, just wanted to point it out ;) Commented Nov 17, 2012 at 18:29

1 Answer 1

2

For the first questions, check out this post.

And the second:

NSString* urlWithoutProtocol = [urlWithProtocol stringByReplacingOccurrencesOfString:@"http://" withString:@""];
Sign up to request clarification or add additional context in comments.

14 Comments

Thanks @NSAddict. But what if I want to add various NSStrings to replace items.. I needed to remove my first line of code to get it working and get urlWithProtocol into urlField.text. I also edited NSString *query
What do you mean? Can you make an example?
I used this code NSString *query = [_urlField.text stringByReplacingOccurrencesOfString:@"http://" withString:@""]; But now I want also to remove @"www." into @""
Then just do [urlWithProtocol stringByReplacingOccurrencesOfString:@"www." withString:@""] again
But what should I place before that line of code? I cant use NSString *query again..
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.