2011-02-23 39 views
2

我解析了一个包含需要在屏幕上显示的字符串的xml。这是执行此操作的代码。无法对存储在NSMutableArray中的字符串使用componentsSeparatedByString

[gTutorialTextList addObject:[attributeDict objectForKey:@"value"]]; 

这里是其中包含的XML文本和gTutorialTextList是我的NSMutableArray属性。

我需要的是我需要分手时\ n进来的字符串。这是执行该操作的代码。

[[gTutorialTextList objectAtIndex:0] componentsSeparatedByString:@"\n"]; 

但现在我无法做到这一点。我没有收到由\ n分开的字符串数组。当我直接把NSString,它工作正常。

请帮忙。我想我正确地表达了我的怀疑。

在此先感谢。

回答

3

你能在索引0就像日志对象的值:

NSString *logString = [gTutorialTextList objectAtIndex:0] 
NSLog(@"-->%@<--", logString); 
NSArray *stringArray = [logString componentsSeparatedByString:@"\n"]; 
NSLog(@"%@", stringArray); 

这应该给你是怎么回事的清晰画面。

+0

这里有输出。 - > \ nSample Text \ nSample Text \ nSample Text < - 。并且文本数组的输出是( “\\ nSample Text \\ nSample Text \\ nSample Text” ) – Aaron 2011-02-23 13:38:18

+3

@Aaron看起来您在输入字符串中有一个真实的反斜杠。试着用[[[gTutorialTextList objectAtIndex:0] componentsSeparatedByString:@“\\ n”];' – Jilouc 2011-02-23 14:29:05

+0

@Jilouc Thankz buddy ...我弄明白了。以前当我直接使用NSString时,这不是问题。因此我在解析的字符串上犯了错误。 – Aaron 2011-02-24 09:10:21

3

我解决了这个问题,把\\ n作为参数在componentSeparatedByString中。

当我们从XML阅读我想,\ n被解释为换行符...

Thankz ..

相关问题