gpt4 book ai didi

iOS NSMutableString 返回奇怪的字符

转载 作者:行者123 更新时间:2023-11-28 19:16:41 27 4
gpt4 key购买 nike

我制作了一个包含几个单词的数组,然后我将所有单词放入一个可变字符串中,然后将这个字符串的每个字符放入一个可变数组中。然而,“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);

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

最佳答案

您调用了 [allTogether release] 但随后又引用了它。通常这会导致您的程序崩溃,但有关 CFMutableArray 支持的一些东西使得这种情况并不总是发生。

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

关于iOS NSMutableString 返回奇怪的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11598432/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com