Iphone 为什么数组处理包含瑞典语ÅÄÖ;使用两个或多个索引的字符?

Iphone 为什么数组处理包含瑞典语ÅÄÖ;使用两个或多个索引的字符?,iphone,objective-c,xcode,nsmutablearray,nsxmlparser,Iphone,Objective C,Xcode,Nsmutablearray,Nsxmlparser,好的,我的问题是每当我从解析器收集数据到一个数组中,其中字符串包含瑞典语字符。在我的例子中 [schemaInfoArray objectAtIndex:3] 应该是"Lördag",但另存为"L"和 包含显示为的字符串的其余部分 @“奥尔达格” 有人想过如何将“Lördag”保存到一个索引中,而不是拆分成几个索引吗?这确实破坏了应该呈现的事物的结构 -(void)parser:(NSXMLParser*)parser foundCharacters:(NSString*)string不保证

好的,我的问题是每当我从解析器收集数据到一个数组中,其中字符串包含瑞典语字符。在我的例子中

[schemaInfoArray objectAtIndex:3] 
应该是"Lördag",但另存为"L"和

包含显示为的字符串的其余部分 @“奥尔达格”

有人想过如何将“Lördag”保存到一个索引中,而不是拆分成几个索引吗?这确实破坏了应该呈现的事物的结构

-(void)parser:(NSXMLParser*)parser foundCharacters:(NSString*)string
不保证包含字符串的完整内容。您需要有一个NSMutableString类实例变量,它可以在对didStartElement和didEndElement的调用之间追加所有foundCharacters。在diEndElement内部,将字符串添加到
schemaInfoArray

-(void)parser:(NSXMLParser*)parser foundCharacters:(NSString*)string
不保证包含字符串的完整内容。您需要有一个NSMutableString类实例变量,它可以在对didStartElement和didEndElement的调用之间追加所有foundCharacters。在DiEndElement内部,将字符串添加到
schemaInfoArray

这是一个,与瑞典语字符无关:

因为字符串可能只是 的总字符内容 当前元素,您应该附加它 对目前的积累 字符,直到元素更改为止

因此,您应该像他们说的那样:使用
NSMutableString
来累积结果,当元素更改时,将缓冲区保存到永久的(最好是)不可变的
NSString

根据要求,这里有一个例子。它是在没有任何IDE的情况下编写的,所以它很可能会工作,但不能保证它会编译或工作

@interface Foo : NSObject<NSXMLParserDelegate> {
    NSMutableString* accumulator;
    NSMutableArray* schemaInfoArray;
    int uppraknare; // whatever 'uppraknare' means
}

/* snip */

@end

@implementation Foo

-(void)parser:(NSXMLParser*)parser foundCharacters:(NSString*)string
{
    // only accumulate characters, until we get notified that we went through
    // the whole XML element
    [accumulator appendString:string];
}

-(void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)nsuri qualifiedName:(NSString*)qName
{
    // we went through the whole element! time to save!
    NSString* immutableResult = [accumulator copy];
    [schemaInfoArray insertObject:immutableResult atIndex:uppraknare];
    uppraknare++;
    [immutableResult release];
    // clear the accumulator for the next element
    [accumulator deleteCharactersInRange:NSMakeRange(0, [accumulator length])];

    /* the rest of your code here */
}

@end
@接口Foo:NSObject{
NSMutableString*累加器;
NSMutableArray*schemaInfoArray;
int uppraknare;//不管“uppraknare”是什么意思
}
/*剪断*/
@结束
@执行Foo
-(void)解析器:(NSXMLParser*)解析器查找字符:(NSString*)字符串
{
//只累积字符,直到我们得到通知,我们通过
//整个XML元素
[字符串:字符串];
}
-(void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)nsuri qualifiedName:(NSString*)qName
{
//我们检查了整个元素!节约时间!
NSString*immutableResult=[累加器副本];
[schemaInfoArray insertObject:immutableResult atIndex:uppraknare];
乌普拉克纳雷++;
[不可变结果发布];
//清除下一个滤芯的蓄能器
[累加器删除字符范围:NSMakeRange(0,[累加器长度])];
/*这里是您的其余代码*/
}
@结束
这是一个字母,与瑞典语字符无关:

因为字符串可能只是 的总字符内容 当前元素,您应该附加它 对目前的积累 字符,直到元素更改为止

因此,您应该像他们说的那样:使用
NSMutableString
来累积结果,当元素更改时,将缓冲区保存到永久的(最好是)不可变的
NSString

根据要求,这里有一个例子。它是在没有任何IDE的情况下编写的,所以它很可能会工作,但不能保证它会编译或工作

@interface Foo : NSObject<NSXMLParserDelegate> {
    NSMutableString* accumulator;
    NSMutableArray* schemaInfoArray;
    int uppraknare; // whatever 'uppraknare' means
}

/* snip */

@end

@implementation Foo

-(void)parser:(NSXMLParser*)parser foundCharacters:(NSString*)string
{
    // only accumulate characters, until we get notified that we went through
    // the whole XML element
    [accumulator appendString:string];
}

-(void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)nsuri qualifiedName:(NSString*)qName
{
    // we went through the whole element! time to save!
    NSString* immutableResult = [accumulator copy];
    [schemaInfoArray insertObject:immutableResult atIndex:uppraknare];
    uppraknare++;
    [immutableResult release];
    // clear the accumulator for the next element
    [accumulator deleteCharactersInRange:NSMakeRange(0, [accumulator length])];

    /* the rest of your code here */
}

@end
@接口Foo:NSObject{
NSMutableString*累加器;
NSMutableArray*schemaInfoArray;
int uppraknare;//不管“uppraknare”是什么意思
}
/*剪断*/
@结束
@执行Foo
-(void)解析器:(NSXMLParser*)解析器查找字符:(NSString*)字符串
{
//只累积字符,直到我们得到通知,我们通过
//整个XML元素
[字符串:字符串];
}
-(void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)nsuri qualifiedName:(NSString*)qName
{
//我们检查了整个元素!节约时间!
NSString*immutableResult=[累加器副本];
[schemaInfoArray insertObject:immutableResult atIndex:uppraknare];
乌普拉克纳雷++;
[不可变结果发布];
//清除下一个滤芯的蓄能器
[累加器删除字符范围:NSMakeRange(0,[累加器长度])];
/*这里是您的其余代码*/
}
@结束

我对Objective C一点也不了解,但问题似乎是由使用8位ASCII扩展名而不是Unicode的编译器造成的。您能发布部分XML吗?如果没有任何真正的样本,就很难看到您在这里做什么。我对Objective C一无所知,但问题似乎是由编译器使用8位ASCII扩展而不是Unicode造成的。您能发布部分XML吗?如果没有任何真实的样本,很难看到你在这里做什么是的,而且整个角色的内容都是Lördag。不是诺尔达格。请你写一个代码示例,为我指出解决这个问题的正确方向好吗?@user679954我已经给出了一个示例。是的,整个字符内容是Lördag。不是诺尔达格。请你写一个代码示例,为我指出解决这个问题的正确方向好吗?@user679954我已经举了一个示例。
@interface Foo : NSObject<NSXMLParserDelegate> {
    NSMutableString* accumulator;
    NSMutableArray* schemaInfoArray;
    int uppraknare; // whatever 'uppraknare' means
}

/* snip */

@end

@implementation Foo

-(void)parser:(NSXMLParser*)parser foundCharacters:(NSString*)string
{
    // only accumulate characters, until we get notified that we went through
    // the whole XML element
    [accumulator appendString:string];
}

-(void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)nsuri qualifiedName:(NSString*)qName
{
    // we went through the whole element! time to save!
    NSString* immutableResult = [accumulator copy];
    [schemaInfoArray insertObject:immutableResult atIndex:uppraknare];
    uppraknare++;
    [immutableResult release];
    // clear the accumulator for the next element
    [accumulator deleteCharactersInRange:NSMakeRange(0, [accumulator length])];

    /* the rest of your code here */
}

@end