0

我正在保存一个NSMutuablearray文本文件,他NSNmbers在里面。

当我打开它(它发送到我的电子邮件)时,我看到:

<integer>-13</integer>
<integer>-80</integer>
<integer>-15</integer>

我只想要没有这个<integer>标志的数字。有办法消除吗?或者把这些数字放在 nsmutuable 中?

代码 :

//add numbers
     for(int i=0;i<417;i++)
     {
         int x= [globals sharedGlobals].bufBuf[i];
         NSNumber* myNumber = [NSNumber numberWithInt: x];
         [samples addObject:myNumber];
     }

//create file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *fullFileName = [NSString stringWithFormat:@"%@/samplesTest.txt", documentsDirectory];
    [samples writeToFile:fullFileName atomically:NO];

谢谢。

4

1 回答 1

0

您可以使用您的数字准备一个字符串,并将其保存到文件中:

NSArray *numbers =
        [NSArray arrayWithObjects:
            [NSNumber numberWithInt:1],
            [NSNumber numberWithInt:2],
            [NSNumber numberWithInt:3],
            nil
        ];
NSString *res = [numbers componentsJoinedByString:@","];
NSError *error;
[res writeToFile:fullFileName atomically:NO encoding:NSUTF8StringEncoding 
                                                      error:&error];
于 2012-05-12T11:29:31.950 回答