1

我对 C# 非常陌生,对文件的写入和读取非常陌生。无论如何,我正在制作一个事件序列,当定时器达到一个数字时将播放事件,同样在该文件中,定时器也将根据存储在文件中的数字调整其速度。我将如何处理,这是解码时该文件的文本。

 [EventSequence]
{
    DisplayName "Default"
    OFFset = 0
    Resolution = 192

}
 [SyncSequence]
{
0 = B 180000
}
 [EventsNotes]
{
0 = E "section Intro"
15168 = E "Note1"
21120 = E "Note2"
26880 = E "Note3"
38976 = E "Note4"
44928 = E "Note5"
}
 [Events]
{
192 = N 0 0
240 = N 0 0
288 = N 0 0
336 = N 0 0
384 = N 4 0
432 = N 0 0
480 = N 0 0
528 = N 0 0
576 = N 3 0
624 = N 0 0
672 = N 0 0
720 = N 0 0
768 = N 4 0
816 = N 0 0
864 = N 0 0
912 = N 0 0
960 = N 2 0
1008 = N 0 0
1056 = N 0 0
1104 = N 0 0
1152 = N 1 0
 }

计时器将非常快,但取决于 Sync 下的值。大值是触发事件的时间,N 0 0 等是事件。“事件说明”的类似设置。其余的只是基本信息。高级中的任何帮助或建议都将受到赞赏。

4

1 回答 1

3

我为您的情况制作了此功能:

public List<string> GetFileKeyValues(string fileName, string key)
        {
            List<string> res = new List<string>();
            try
            {
                if (!string.IsNullOrEmpty(key))
                {
                    using (System.IO.StreamReader tr = new System.IO.StreamReader(fileName))
                    {
                        bool keyFound = false;
                        while (!tr.EndOfStream)
                        {
                            string s = tr.ReadLine().ToLower();
                            if (s.Contains(key.ToLower())) keyFound = true;
                            else
                            {
                                if (keyFound)
                                {
                                    if (!s.Contains("{") && !s.Contains("}")) res.Add(s);
                                    if (s.Contains("}")) break;
                                }
                            }
                        }
                        tr.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return res;
        }

用法假设我们想要获取[SyncSequence]值:

List<string> res = GetFileKeyValues(@"C:\t.txt", "[SyncSequence]");
if(res != null && res.Count > 0) 
{
  //Do Something with res[0], it will return 0 = B 180000
  //So you split it by "=" to get B 180000 or any thing you want... 
} 
于 2012-04-13T07:06:21.527 回答