2010-02-03 82 views
-1

就在我問過如何通過指定鍵將文件輸入轉換爲散列表之前,我真的很抱歉,實際上我需要從文本文件中分別確定鍵和值,並將其放入我的哈希表。即將文件複製到Hashtable

This is text file: 
LENOVA = Class_Name 
DELL = Class_Name 
WIPRO = Class_Name 
SAMSUNG = Class_Name 

需要將它作爲鍵/值對加入散列表,最後從散列表加載類。

In HashTable it has to store in this way: 
Key   Value 
LENOVA Class_Name 
DELL  Class_Name 
WIPRO  Class_Name 
SAMSUNG Class_Name 

如何在Objective-C中做到這一點?給我一些想法繼續。

回答

0

如果你被允許改變輸入的文本文件,它包含:

"LENOVA" = "Class_Name"; 
"DELL" = "Class_Name"; 
"WIPRO" = "Class_Name"; 
"SAMSUNG" = "Class_Name";

然後,你可以簡單地做:

NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:@"myfile.txt"]; 
+0

大!!!!我可以通過NSLog訪問鍵的值(@「DICOM =%@,[dict objectForKey:@」DICOM「]);感謝Dreamlax ...我可以在XCode中查看這個散列表嗎?我的意思是以什麼格式它被儲存在什麼地方? – suse 2010-02-03 06:47:23