0

给定一个对象列表,我将它们保存到这样的文本文件中:

public void Save(PhoneBook pb)
{
   foreach (PhoneBookGroup item in pb.Items)
   {
        File.WriteAllText(path, item.GroupName + "@");
        foreach (Contect contect in item.Items)
       {
           File.WriteAllText(path, "Group :" + item.GroupName + "#"+
                                   "Name : " + contect.Name + "$" +
                                   "Number : " + contect.Number + "$" +
                                   "Addres : " + contect.Addres + "$");
       }
   }
} 

结果是: Group :group Aaa#Name : Ziv$Number : 1$Addres : Sokolov$

现在我想从该文件加载,同时保持逻辑并将每个组添加到列表中。使用查找(# 代表对象名称和 $ 代表属性名称)示例的字符查找器:

Aaa(object)  
ziv(attributes)  
1(attributes)  
sokolov(attributes)

等等

bbb(object)  
jon(attributes)  
2(attributes)  
somewhere(attributes)   

.

public void Load()
{
   List<PhoneBook> phoneBookList = new List<PhoneBook>();

   string line = File.ReadAllText(path);
   foreach (var item in line)
   {

   }
   return phoneBookList;

}

4

0 回答 0