0

I have an output string in this format . I need to format the string such that i can display the URL separately and my Content, the description separately. Is there any functions , so i can format them easily ? The code :

            NSLog(@"Description %@", string);

The OUTPUT String:

    2013-07-28 11:13:59.083 RSSreader[4915:c07] Description         
    http://www.apple.com/pr/library/2013/07/23Apple-Reports-Third-Quarter-Results.html?sr=hotnews.rss
    Apple today announced financial results for its fiscal 2013 third quarter ended
    June     29, 2013. The Company posted quarterly revenue of $35.3 billion and quarterly 
    net profit of $6.9 billion, or $7.47 per diluted share. 
    Apple sold 31.2 million iPhones, which set a June quarter record. 
Siva
  • 509
  • 6
  • 22

3 Answers3

1

You should extract URL from string, then display it in formatted way.

A simple way to extracting URL is regular expressions (RegEX).

After extracting URL you can replace it with nothing:

str = [str stringByReplacingOccurrencesOfString:extractedURL
                                     withString:@""];

You can use this : https://stackoverflow.com/a/9587987/305135

Community
  • 1
  • 1
AVEbrahimi
  • 17,993
  • 23
  • 107
  • 210
0

If description string separated by line break (\n), you can do this:

NSArray *items = [yourString componentsSeparatedByString:@"\n"];
Sergei Belous
  • 4,708
  • 1
  • 16
  • 20
0

Regex is a good idea.

But there is a default way of detecting URLs within a String in Objective C, NSDataDetector. NSDataDetector internally uses Regex.

NSString *aString = @"YOUR STRING WITH URLs GOES HERE"
NSDataDetector *aDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *theMatches = [aDetector matchesInString:aString options:0 range:NSMakeRange(0, [aString length])];
for (int anIndex = 0; anIndex < [theMatches count]; anIndex++) {
    // If needed, Save this URL for Future Use.
    NSString *anURLString = [[[theMatches objectAtIndex:anIndex] URL] absoluteString];

    // Replace the Url with Empty String
    aTitle = [aTitle stringByReplacingOccurrencesOfString:anURLString withString:@""];
}
Roshit
  • 1,589
  • 1
  • 15
  • 37