Wednesday, September 25, 2013

Data storage, read and delete

I am now trying to store the contents of customer input to a file and then read it. However, the number of data in the form of a character channeling saved in the same file ...... with line and comma-separated ...... How can I delete read with sub-section.

For example:

 
/ / This has three rows of data, in fact, on a date to save
event2012-02-02, a, xxx
2012-02-03, two, yyy
2012-02-04, three, zzz
/ / I can now do storage, but how to read and operate it separately?
/ / Do database,


Reply:
/ / Respectively NSData and NSString, NSMutableDictionary to read the contents of the file
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentsDirectory = [paths objectAtIndex: 0];
NSString * filepath = [documentsDirectory stringByAppendingPathComponent: @ "reads the file name"];
NSArray * fileData = [[NSArray alloc] initWithContentsOfFile: filepath];

NSString * str0 = [array objectAtIndex: 0];
NSString * str1 = [array objectAtIndex: 1];
NSString * str2 = [array objectAtIndex: 2];
/ / Delete the second data
NSArray * newArray = [NSArray arrayWithObjects:
@ "Str0", @ "\ n \ r", @ "str2", nil];

<4> to write data files
NSString * fileName = [[filePath objectAtIndex: 0] stringByAppendingPathComponent: DBNAME];

[NewArray writeToFile: fileName atomically: NO];

Code similar to deal with it, should be achievable.

No comments:

Post a Comment