I want to read data from a CFG (configuration file). How do I read it? Is it the same as XML?
lets say i have this text messge in text.cfg
Restaurant,tab0.png,tab0/index1.html Shop,tab1.png,tab1/index1.html Office,tab2.png,tab2/index1.html Apartment,tab3.png,tab3/index1.html
now i want to parse them and create 4 dynamic button each have their own Png and open html file on click .
so whats the best way to parse them( xml or something else) ??as i want this to be generic and i have to update this data as well
How is the file formatted?
If the file is an XML document containing the configuration details then you can read it in and parse it with an XML parser the same as you do with other XML files.
If the file is formatted differently, Eg., using comma or tab delimiters, then you'll have to write your own code to parse the configuration details.
There are a few options to read in a file, one of which follows:
NSData *fileData = [[NSData alloc] initWithContentsOfFile:filePath];
NSString *fileText = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];
Don't forget to release them when you're done. Also this code makes some assumptions.
- You know the file path
- The file is using UTF8 encoding