writing to a file on the -iphone-unwanted symbols
I have an array and i am writing it to a file using :
memoryString=[memoryString stringByAppendingString:WhatsTheTimeNow];
[memoryFile addObject:memoryString];
[memoryFile writeToFile:fullFileName atomically:NO];
the log is ok , But what i get on the log file is also some more symbols :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string> Touch Event: leftEye --- ר10 10:33:10---2011</string>
<string> Sensor Event: rightHand --- א10 10:33:26---2011</string>
<string> Sensor Event开发者_如何学Python: rightHand --- ר10 10:33:29---2011</string>
<string> Sensor Event: rightLeg --- א10 10:33:32---2011</string>
<string> Touch Event: leftEye --- ר10 10:33:34---2011</string>
<string> Touch Event: leftEye --- א10 10:33:36---2011</string>
</array>
</plist>
The problem, is that i dont want that <string>
,<array>
symbols at the start and end , and the 3 openning lines.
how do i get rid of this symbols ??
thanks alot .
The writeToFile
method will automatically generate a .plist
which is very convenient for reading it back in. If you would like to roll your own,
NSMutableString *file = [NSMutableString string];
for (NSString *s in memoryFile) {
[file appendFormat:@"%@\n", s];
}
[memoryFile writeToFile:fullFileName atomically:NO
encoding:NSUTF8StringEncoding error:nil];
Note that writeToFile:atomically:
is deprecated.
Your strange characters must stem from some issue with the assignment to memoryString
.
Those "symbols" are what makes your file a .plist
, which is what is created when you call writeToFile:
on an NSArray
. If you want a custom output (which you won't be able to read back in to an array using standard functionality), you'll have to write it yourself, probably using NSString
's writeToFile:
method instead.
精彩评论