Hey, my first question! I've been able to code up most of this RSS reader without enlisting help (through a lot of searches through stackoverflow!) but I'm stumped here.
NSString *urlbase = [[NSString alloc] initWithFormat:[links3 objectAtIndex:indexPath.row]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlbase]]; NSCharacterSet *whitespaces = [NSCharacterSet whitespaceCharacterSet]; NSPredicate *noEmptyStrings = [NSPredicate predicateWithFormat:@"SELF != ''"];
NSArray *parts = [urlbase componentsSeparatedByCharactersInSet:whitespaces]; NSArray *filteredArray = [parts filteredArrayUsingPredicate:noEmptyStrings]; urlbase = [filteredArray componentsJoinedByString:@" "];
NSLog(@"%@ %i" , urlbase, 4353); [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlbase]]; The links3 array is a NSMutableArray with strings. The first few lines work flawlessly in eliminating the space at the beginning each string from that array, which is stored in 'urlbase' so they look fine when they come out. When we NSLog urlbase, we see:
http://www.feedzilla.com/r/D7E6204FEDBFE541314B997AAB5D2DF9CBA2EFEE
But, when we use: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlbase]]
We see: http://www.feedzilla.com/r/D7E6204FEDBFE541314B997AAB5D2DF9CBA2EFEE%0A
How can I fix this? Can I remove those tail elements somehow? Thanks!
Working code:
NSMutableArray *links3 = [[NSMutableArray alloc] init];
RSSAppDelegate *appDelegate = (RSSAppDelegate *)[[UIApplication sharedApplication] delegate]; links3 = appDelegate.links; NSLog(@"%@ %i", [links3 objectAtIndex:indexPath.row], 3453); NSString *urlbase = [[NSString alloc] initWithFormat:[links3 objectAtIndex:indexPath.row]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlbase]]; NSCharacterSet *whitespaces = [NSCharacterSet whitespaceCharacterSet]; NSPredicate *noEmptyStrings = [NSPredicate predicateWithFormat:@"SELF != ''"];
NSArray *parts = [urlbase componentsSeparatedByCharactersInSet:whitespaces]; NSArray *filteredArray = [parts filteredArrayUsingPredicate:noEmptyStrings]; urlbase = [filteredArray componentsJoinedByString:@" "];
NSLog(@"%@ %i" , urlbase, 4353);
NSLog(@"%@ %i" , urlbase, 345346); NSString* fixed = [urlbase stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
NSURL *hellothere = [NSURL URLWithString:fixed]; NSLog(@"%@ %i", hellothere, 54);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:fixed]];
Hey, I didn't say it was pretty. Thanks Diederik Hoogenboom!