Simplest possible key/value pair file parsing in .NET

前端 未结 5 1722
闹比i
闹比i 2021-01-17 19:07

My project requires a file where I will store key/value pair data that should be able to be read and modified by the user. I want the program to just expect the keys to be t

5条回答
  •  抹茶落季
    2021-01-17 19:32

    Format the file this way:

    key1=value1
    key2=value2
    

    Read the entire file into a string (there is a simple convenience function that does that, maybe in the File or string class), and call string.Split('='). Make sure you also call string.Trim() on each key and value as you traverse the list and pop each pair into a hashtable or dictionary.

提交回复
热议问题