jwknz
jwknz

Reputation: 6824

ios - getting part of an NSString

I have seen this question that talks about getting the last part of a NSString.

I require a slight variation on this.

How do I get everything after the http://

Would be good if it was almost as simple as 1 line of code:-)

Cheers

Upvotes: 0

Views: 881

Answers (4)

Justin Paulson
Justin Paulson

Reputation: 4388

May want to actually check that you are using "http://" at the front and not replace it in every instance. How about this:

if([[str substringToIndex:@"http://".length] isEqualToString:@"http://"])
    str = [str substringFromIndex:@"http://".length];

That would be more robust and will actually make sure it starts with "http://" and not replace every instance of it.

Upvotes: 0

Scott Bossak
Scott Bossak

Reputation: 2501

NSString *originalString = @"http://google.com";
NSString *substring = [originalString stringByReplacingOccurrencesOfString:@"http://" withString:@""];

Upvotes: 0

Benedict Cohen
Benedict Cohen

Reputation: 11920

substringFromIndex:. You'd be wise to do some bounds checking too. Also, I'd advice taking a look at the documentation before asking a question.

Upvotes: 1

Abhishek
Abhishek

Reputation: 2253

NSString *str = @"http://www.abc.com/news/read/welcome-new-gig/03276";

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

hope this will help you.....

Upvotes: 2

Related Questions