views:

77

answers:

1

I am trying to create an NSArray of Strings from a text file.

Here's the code i've been using:

NSString *title = @"facts";
    NSString *type = @"txt";
    NSString *seperation = @"/n";
    NSMutableArray *factArray = [[NSArray alloc] initWithArray:[[NSString stringWithContentsOfFile:[[NSBundle mainBundle] 
                                                            pathForResource:title ofType:type] 
                                                                    encoding:NSMacOSRomanStringEncoding error:NULL] 
                                                         componentsSeparatedByString:seperation]];

But it seems to give some extra objects with no text in, i need to fix this. Just if it helps this the text file I've been using it with:

/nFeet sizes in England are measured in Barleycorns. /n

Elephants laugh and cry. /n

Trousers kill 12 people a year. /n

The lion that roars in the MGM logo is called Volney. /n

The wife of a Sultan is called a Sultana. /n

Brad Pitt's real name is William. /n

There are more than 5000 ladybird species. /n

US lavatories are 100 times more dangerous than British ones. In 1996, 43,687 Americans were hospitalized after toilet disasters. /n

The statue of liberty is made of bronze and was given to the Americans by the French. /n

The Irish gave bagpipes to the Scots as a joke. It back fired! /n

Your foot is the same length as the distance between your wrist and elbow. /n

A rat can swim non-stop for 72 hours. /n

The odds of being killed in a car crash in Britain are the same as being killed in an accident inside your own home: 1 in 10,000. /n

In 1996, 12 people in Britain were rushed to hospital after a paperclip incident. /n

A: 

How about logging the array to the console (or printing it using "po factArray")? The extra objects might be empty lines, maybe? If so, you can just remove all objects (strings) that isEqualToString:@"" ...

Joshua Nozzi
When I log the array using `for (NSString *text in self.facts)``{`` NSLog``(@"%@",`` text);`` }``it only shows 14 items when the count shows 16.
Joshua
Post it. Append the output to your question so we can see what you see.
Joshua Nozzi
Here's what I see. http://cl.ly/5f6757054624b3406fb6
Joshua