// Append a string to the content of a Cell IF a certain corresponding Cell in the same column or a different column matches a Regex (ex: if "Description" contains "Credit" then append a "-" to column "Amount") public int Append_If_Column_Matches_Pattern(String InputFile, String ColumnNameToMatch, String RegExPattern, String ColumnNameToModify, String StringToAppend, Boolean AppendAtEnd) { CsvUtils cu = new CsvUtils(); cu.SetFile(InputFile); int CntMods = 0; int ColumnIndex = cu.Get_Column_Index(ColumnNameToMatch); int ColumnIndexToModify = cu.Get_Column_Index(ColumnNameToModify); if (ColumnIndex < 0 || ColumnIndexToModify < 0) { return(-1); } foreach (KeyValuePair <int, List <String> > entry in cu.dict) { //Console.WriteLine("Debug Column Index | Name: " + ColumnIndex + ":" + ColumnName); String MyLine = cu.Get_Line_Content(entry.Key); String CellValueToCheck = entry.Value[ColumnIndex]; var pattern = @RegExPattern; var matches = Regex.Matches(CellValueToCheck, pattern); if (entry.Key > 0 && matches.Count != 0) // not first line AND match { String OriginalValueOfCell = entry.Value[ColumnIndexToModify]; String NewValueCell = ""; if (OriginalValueOfCell.StartsWith("\"")) { NewValueCell = cu.ReplaceFirst(OriginalValueOfCell, "\"", "\"" + StringToAppend); } else { NewValueCell = StringToAppend + OriginalValueOfCell; } entry.Value[ColumnIndexToModify] = NewValueCell; CntMods++; } } cu.Save_File_As_CSV(InputFile); return(CntMods); }