How to match the first occurrence of a character and split it

后端 未结 5 1337
忘掉有多难
忘掉有多难 2021-01-26 16:24

I have a text file from which I want to store Keys and Values in a String array.

In this case, Key is something like &

5条回答
  •  半阙折子戏
    2021-01-26 16:26

    On this way you can read each line of the text file. You fill the json with Key = until the ":" Value= From the ":"

    Dictionary yourDictionary = new Dictionary();
    string pathF = "C:\\fich.txt";
    StreamReader file = new StreamReader(pathF, Encoding.Default);
    string step = "";
    List stream = new List();
    while ((step = file.ReadLine()) != null)
    {
        if (!string.IsNullOrEmpty(step))
        {
            yourDictionary.Add(step.Substring(0, step.IndexOf(':')), step.Substring(step.IndexOf(':') + 1));
        }
    }
    

提交回复
热议问题