NSXMLParser 的修剪字符
修剪 NSXMLParser
的 foundCharacters
中的字符的正确方法是什么?
我发现了很多这样做的例子:
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
NSString *characters = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// Append to previous characters of the same element
}
然而,当我运行上面的代码时,后跟非 ASCII 字符的空格会被修剪。示例:“this é”将变为“thisé”。
What is the right way to trim characters in foundCharacters
of NSXMLParser
?
I've found many examples that do it like this:
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
NSString *characters = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// Append to previous characters of the same element
}
Yet a space followed by a non-ASCII character is trimmed when I run the above. Example: "this é" will become "thisé".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许是巧合。
请参阅
parser:foundCharacters:
的讨论如果你修剪
this
中的空格(末尾有一个你看不到的空格),然后从é
中删除,你最终会得到thisé< /代码>。
我从未使用过 NSXMLParser,但也许您应该修剪
parser:didEndElement:namespaceURI:qualifiedName:
中的字符串。据我了解,该元素届时将完成。但我只是猜测。
maybe by coincidence.
See the discussion of
parser:foundCharacters:
And if the you trim the whitespace from
this
(with a space at the end you can't see) and then fromé
you will end up withthisé
.I've never used NSXMLParser, but maybe you should trim the string in
parser:didEndElement:namespaceURI:qualifiedName:
. From what I understand, the element will be completed then.But I'm just guessing.
这是我过去用来修剪空白的方法,没有任何问题。
唯一的区别是它使用稍微不同的空白字符集。
This is what I've used in the past to trim whitespace without any problems.
The only difference is that It's using a slightly different whitespace character set.