How to read embedded resource text file

前端 未结 22 2333
悲&欢浪女
悲&欢浪女 2020-11-21 06:03

How do I read an embedded resource (text file) using StreamReader and return it as a string? My current script uses a Windows form and textbox that allows the

22条回答
  •  礼貌的吻别
    2020-11-21 07:00

    I read an embedded resource text file use:

        /// 
        /// Converts to generic list a byte array
        /// 
        /// byte array (embedded resource)
        /// generic list of strings
        private List GetLines(byte[] content)
        {
            string s = Encoding.Default.GetString(content, 0, content.Length - 1);
            return new List(s.Split(new[] { Environment.NewLine }, StringSplitOptions.None));
        }
    

    Sample:

    var template = GetLines(Properties.Resources.LasTemplate /* resource name */);
    
    template.ForEach(ln =>
    {
        Debug.WriteLine(ln);
    });
    

提交回复
热议问题