Contents of file as input to hashtable in Objective-C -
I know how to read the contents of the file in Objective-C, but how to take it as the input of a hashtable text file See content as test.txt
Lenova HCL Wipro Del
Now I need to read the key values in my Hashbab as a pair < / P>
main VAlue 1 LENOVA 2 HCL 3 WIPRO 4 DELL
< P> you have a string in your file Want to parse and assign each element with a key in this array. This can help you get in the right direction.
NSString * wholeFile = [NSString stringWithContentsOfFile: @ "filename.txt"]; NSERRE * line = [fullfile components declared bestselling: @ "\ n"]; NSMutableDictionary * dict = [ability with NSMutableDictionary dictionary: [line count]]; Int counter = 1; (Line in NSSS * line) {if ([line length]) {{dict setObject: for line forkey: [NSString stringWithFormat: "% d", counter]]; // If you want as the `NSNumber` key, then use this line instead: // [dict setObject: for lineKey: [NSNumber Numberless: Counter]]; Counter ++; }}
Keep in mind that this is not the most effective way to parse your file. It uses the refractive method stringWithContentsOfFile:
.
To get a back line, use it:
NSString * myLine = [dict objectForKey: @ "1"]; // If you have used the `nsnumber` class for the key, then use it: // NSString * myLine = [dict objectforekey: [NSNumber number: 1]];
Comments
Post a Comment