/// <summary> /// Parse Record as Field(Column) /// </summary> /// <param name="record">record text</param> /// <returns>List of fields</returns> private string[] ParseRecordAsFields(string record) { var pattern = string.Format(Constants.StringPattern, Regex.Escape(FieldDelimeter.ToString(CultureInfo.InvariantCulture)), Regex.Escape(QuoteDelimeter.ToString(CultureInfo.InvariantCulture))); //Split record using pattern return(Regex.Split(record, pattern)); }
/// <summary> /// Get Content Field value from record and remove content text in record /// </summary> /// <param name="record">record text</param> /// <param name="fieldNumber">Field index</param> /// <returns>Field value</returns> public string GetContentFieldValueAndRemoveContentInRecord(ref string record, int fieldNumber) { var fieldData = ParseRecordAsFields(record); if (fieldData.Count() > fieldNumber) { string content = fieldData[fieldNumber]; fieldData[fieldNumber] = string.Empty; //Remove content text record = string.Join(FieldDelimeter.ToString(CultureInfo.InvariantCulture), fieldData); //reconstruct record after remove content text var contentValue = CleanFieldsData(new[] { content }); return(contentValue[0]); } return(string.Empty); }