/// <summary> /// Creates an instance of constructor file to read the file /// </summary> /// <param name="data">Stream data</param> /// <param name="separator">Character used to separate column</param> /// <param name="hasHeader">If there is header in file</param> /// <param name="skipEmptyLine">If empty lines it's skipped</param> public ReadFile(Stream data, string separator, bool hasHeader, bool skipEmptyLine = true) { _currentLinePosition = 0; _lines = new List <LineBuilder>(); using (var reader = new StreamReader(data, Encoding.GetEncoding("iso-8859-1"))) { string line = null; while ((line = reader.ReadLine()?.Trim()) != null) { if (skipEmptyLine && line.Trim() == string.Empty) { continue; } var fileLine = new LineBuilder(); var words = line.Split(new string[] { separator }, StringSplitOptions.None); fileLine.AddTexts(words); fileLine.ResetCurrentPosition(); _lines.Add(fileLine); } } if (hasHeader && _lines.Count > 0) { _header = _lines[0]; _lines.RemoveAt(0); } }
/// <summary> /// Adds texts to the current line in columns available sequentially. /// </summary> /// <param name="texts">Texts to be insert.</param> public void AddTexts(params string[] texts) => _currentLine.AddTexts(texts);