这个问题是这个问题的延伸。
现在我使用下面的代码来解析 xml 数据,
-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
rValue = [[NSMutableString alloc]init];
isTag = FALSE;
if ([elementName caseInsensitiveCompare:@"BusinessName"] == NSOrderedSame)
isTag=YES;
}
-(void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)strin{
if (isTag)
[rValue appendString:strin];
}
-(void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName caseInsensitiveCompare:@"BusinessName"] == NSOrderedSame)
[myarray addObject:rValue];
}
-(void) parserDidEndDocument:(NSXMLParser *)parser
{
NSLog(@"%@",myarray);
}
rValue
是一个 NSMutablestring;
打印我的数组后,它看起来像这样,
(
"Book Store\n ",
"Birch river grill\n ",
"PIC\n ",
"Drink Juice\n ",
"Cofee Cafee\n ",
"Diag Block\n ",
"Delici Store\n ",
"Rubbit Rabbit\n\n\n ",
"Spoon Fork\n ",
"Travel Sea\n\n ",
"Water Melocious\n\n\n ",
"Lazee Fish\n\n\n\n ",
"Allow\n ",
"Enjoy Traveling\n ",
"Grwing Three\n ",
"Diz Cow\n\n ",
"Wheeler Marine\n\n\n "
)
如何防止将\n
s 添加到 NSMutable 字符串?即,我需要检查字符串是否有\n
?
有时这些 \n 出现在 NSMutableString 的前缀,任何建议将不胜感激。