using System.Collections.Generic; using System.Text; namespace ChanSort.Api; public static class CsvFile { public static IList Parse(string line, char separator) { if (line.EndsWith("\n")) line = line.Substring(0, line.Length - 1); if (line.EndsWith("\r")) line = line.Substring(0, line.Length - 1); List tokens = new List(); if (line.Length == 0) return tokens; bool inQuote = false; StringBuilder token = new StringBuilder(); for(int i = 0, len=line.Length; i= 0) // characters that require the value to be quoted needQuotes = true; sb.Append(c); } if (needQuotes) sb.Insert(0, "\"").Append("\""); return sb.ToString(); } public static string ToLine(IEnumerable values, char separator, bool needQuotes = false) { if (values == null) return ""; var sb = new StringBuilder(); foreach (var value in values) { if (sb.Length > 0) sb.Append(separator); sb.Append(ToValue(value, needQuotes)); } return sb.ToString(); } }