Hello everyone ..
iam kind of new to iOS development as well as iPhonedev sdk .so if there is any problem with my post do tell .. i will correct them.
I want to retrieve strings form the text file i have ..
the file is within my application main bundle
its content are
#start word1 First word end word2 Second word end //lots of things to be added later
Code:
path = [[NSBundle mainBundle]pathForResource:@"words" ofType:@"rtf"];
if(path)
{
NSLog(@"path exists");
}
NSError *error = nil;
NSString *file = [[NSString alloc]initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
if(error)
{
NSLog(@"error");
}
NSString *finalword= [[NSString alloc]init ];
NSString *startfrom = [[NSString alloc] initWithFormat:@"word%i",i+1];
i++;
NSLog(@"%@",startfrom);
NSString *wordoftheday = [[NSString alloc]init ];
NSScanner *scanner = [NSScanner scannerWithString:file];
[scanner scanUpToString:startfrom intoString:nil];
[scanner scanUpToString:@"end" intoString:&wordoftheday];
finalword = [wordoftheday substringFromIndex:[startfrom length]];
NSLog(@"%@",finalword);
Word.text = finalword;
code is working fine but it leaves me with memory management issues.
also this method is in my viewdidload .
i want the label to change text when user click a button .. i will have to write the same code again in that method which leaves me with more memory issue.
Kindly help