Ed.BudgetVisualizer.Logic/ParserLogic.cs
/// <summary>
/// Splits a line into fields and cleans each field from surrounding double quotes.
/// </summary>
/// <param name="line">Line to split and clean.</param>
/// <param name="separator">Separator character.</param>
Splits a line into fields and cleans each field from surrounding double quotes.
Splits a line into fields and cleans each field from surrounding double quotes .
private string[] SplitAndClean(string line, char separator)
        {
            var fields = new List<string>();
            foreach (Match match in Regex.Matches(line, $"(?:\"(.*?)\"|(\\d+.*?)){separator}"))
            {
                fields.Add(!string.IsNullOrEmpty(match.Groups[1].ToString())
                    ? match.Groups[1].ToString().Trim()
                    : match.Groups[2].ToString().Trim());
            }
            return fields.ToArray();
        }
private string [ ] SplitAndClean ( string line , char separator ) { var fields = new List < string > ( ) ; foreach ( Match match in Regex . Matches ( line , $" (?: \" (.*?) \" |( \\ d+.*?)) { separator } " ) ) { fields . Add ( ! string . IsNullOrEmpty ( match . Groups [ 1 ] . ToString ( ) ) ? match . Groups [ 1 ] . ToString ( ) . Trim ( ) : match . Groups [ 2 ] . ToString ( ) . Trim ( ) ) ; } return fields . ToArray ( ) ; }
Splits a line into fields and cleans each field from surrounding double quotes.
Splits a line into fields and cleans each field from surrounding double quotes .
// Match either fields surrounded in quotes or fields without quotes // Both fields end with the separator // Add whichever group matched
line
string
Line to split and clean.
Line to split and clean .
separator
char
None