I make an array of several words, then I put all words into a mutable string, and then a mutable array of every character of this string. However, “wordSplitted” that is a mutable array of the characters give random scrambled characters at each startup of app in Simulator, showing in the log:
2012-07-22 09:12:01.108 xxx[4484:b603] wordSplitted contains: (
"",
"",
"\U221e",
"-",
G,
N,
P,
"",
""
)
It should be 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);
How can I display normal characters like alphabets?
You call
[allTogether release]but then reference it later on. Normally this would cause your program to crash, but something about theCFMutableArraybacking makes this not always happen.Basically, don’t release the array until you’re sure you’re done using it.