0

我制作了一个由几个单词组成的数组,然后将所有单词放入一个可变字符串中,然后将该字符串的每个字符组成一个可变数组。但是,作为可变字符数组的“wordSplitted”在模拟器中每次启动应用程序时都会给出随机加扰字符,显示在日志中:

2012-07-22 09:12:01.108 xxx[4484:b603] wordSplitted contains: (
    "",
    "",
    "\U221e",
    "-",
    G,
    N,
    P,
    "",
    ""
)

应该是 b, i, l, h, u, k, s, k, j。

   NSArray *threeWords = [NSArray arrayWithObjects:@"bil", @"huk", @"skje", nil];


    NSMutableString *allTogether = [[NSMutableString alloc]init];

    /*
    for (NSString *s in threeWords)
    {
        [allTogether appendString:s];
    }
     */

    for (int b = 0; b < [threeWords count]; b++)
    {
        [allTogether appendString:[threeWords objectAtIndex:b]];
    }
    NSLog (@"allTogether contains %@", allTogether);

    //[threeWords release];
    [allTogether release];

    NSMutableArray *wordSplitted = [[NSMutableArray alloc]init];

//this function gives me headache
        for (int a = 0; a < 9; a ++)
        {
            //gives also scrambled characters

        //[wordSplitted addObject:[NSString stringWithFormat:@"%C",[allTogether characterAtIndex:a]]];

        NSRange range = {a,1};

        [wordSplitted addObject:[allTogether substringWithRange:range]];

    }

    NSLog (@"wordSplitted contains: %@", wordSplitted);

如何显示字母等普通字符?

4

2 回答 2

3

你打电话[allTogether release],但稍后再引用它。通常这会导致你的程序崩溃,但一些关于CFMutableArray支持的事情并不总是会发生。

基本上,在确定使用完毕之前不要释放阵列。

于 2012-07-22T07:22:17.180 回答
1

关于字符串拆分

http://www.idev101.com/code/Objective-C/Strings/split.html

于 2012-07-22T07:24:48.270 回答