问题
Could someone please show how i could parse a ics file using NSScanner? (Iphone App)
e.g: if the .ics file was at this URL http://www.ibz.com/data/12345.ics (not a real URL!!!)
How would i firstly save the .ics file into my iphone app
and then secondly how would i parse the .ics file using NSScanner??
Please provide code examples..
回答1:
Code examples to do this completely and well would be quite extensive, and SO isn't the place for large sample applications. With that in mind, the general solutions would be:
- Use a NSURLRequest and NSURLConnection to get an HTTP connection to download the file; store it as an NSData object built during delegate calls from the NSURLConnection. Once it's completely downloaded, convert it to an NSString for parsing. The URL Loading System Programming Guide has a number of examples - look for NSURLConnection and asynchronous requests.
- To parse the .ics file (which at this point is available as an NSString), you'll first need to figure out the expected format of the file. Wikipedia seems to have a couple examples of how .ics files store data. Basically you'll want to go through and scan strings separated by the various separators the file format uses (looks to be mostly colons).
If you have more specific questions, you'll probably get much more specific answers - give it a shot and ask more if you get stuck!
来源:https://stackoverflow.com/questions/5111919/how-to-use-nsscanner-to-parse-ics-file