2011-02-23 38 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 ..

相關問題