How to add "http: //" to the string (if missing)

I have a string [currentTweet pic]

that needs to be an image url (parsed from an XML file). The problem is that some of the links do not contain the "http: //" url, so some images are not displayed. How can I add "http: //" where it is missing?

Any help is greatly appreciated! THH

+3


source to share


1 answer


I assume you mean NSString

here by contrast NSURL

.

NSString *picURL = [currentTweet pic];
if (![picURL hasPrefix:@"http://"]) {
    picURL = [@"http://" stringByAppendingString:picURL];
}

      



Not sure if twitter ever uses https

pic urls, but you can also check on https://

to be sure.

+13


source







All Articles