Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Searching string from rtf file within NSbundle

ShubhankShubhank Posts: 13Registered Users
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

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
Sign In or Register to comment.