示例#1
0
        public static CSVRow FindRow(CSVData i_Source, string i_ColumnName, string i_ValueMatch, bool caseSensitive, bool containsMatch, int recordStartIndex = 0)
        {
            var result = new CSVRow(i_Source, null, -1);

            if (recordStartIndex < 0)
            {
                recordStartIndex = 0;
            }
            System.StringComparison comparisonType = caseSensitive ? System.StringComparison.Ordinal : System.StringComparison.OrdinalIgnoreCase;
            var columnNames = i_Source.ColumnNames;
            int columnCount = columnNames.Length;

            for (int i = 0; i < columnCount; ++i)
            {
                bool columnMatch = string.Compare(columnNames[i], i_ColumnName, comparisonType) == 0;
                if (columnMatch)
                {
                    int recordCount = i_Source.ContentRowCount;
                    for (int j = recordStartIndex; j < recordCount; ++j)
                    {
                        string[] recordValues = i_Source.GetContentRow(j);
                        string   value        = recordValues[i];
                        bool     foundRecord  = false;
                        if (containsMatch)
                        {
                            foundRecord = value.IndexOf(i_ValueMatch, comparisonType) >= 0;
                        }
                        else
                        {
                            foundRecord = string.Compare(value, i_ValueMatch, comparisonType) == 0;
                        }
                        if (foundRecord)
                        {
                            result.Values = recordValues;
                            result.Index  = j;
                            break;
                        }
                    }
                    break;
                }
            }

            return(result);
        }
示例#2
0
        public static CSVData CreateFromString(string content)
        {
            CSVData result = null;

            fgCSVReader.LoadFromString(
                content,
                (int i_LineIndex, List <string> i_Line) =>
            {
                if (i_LineIndex == 0)
                {
                    result = new CSVData(i_Line.ToArray());
                }
                else
                {
                    result.AddContentRow(i_Line.ToArray());
                }
            }
                );

            return(result);
        }
示例#3
0
        public CSVColumn(CSVData i_Source, string i_Name)
        {
            Source = i_Source;
            Name   = i_Name;
            Values = null;
            var columnKeys = i_Source.ColumnNames;

            for (int i = 0; i < columnKeys.Length; ++i)
            {
                if (i_Name == columnKeys[i])
                {
                    int      recordCount  = i_Source.ContentRowCount;
                    string[] columnValues = new string[recordCount];
                    for (int j = 0; j < recordCount; ++j)
                    {
                        columnValues[j] = i_Source.GetContentCell(j, i);
                    }
                    Values = columnValues;
                    break;
                }
            }
        }
示例#4
0
        public static CSVData Parse(string content)
        {
            CSVData result = null;

            if (!string.IsNullOrEmpty(content))
            {
                Action <int, List <string> > ReadLineFunc = (int i_LineIndex, List <string> i_Line) =>
                {
                    if (i_LineIndex == 0)
                    {
                        result = new CSVData(i_Line.ToArray());
                    }
                    else
                    {
                        result.AddContentRow(i_Line.ToArray());
                    }
                };

                fgCSVReader.LoadFromString(content, new fgCSVReader.ReadLineDelegate(ReadLineFunc));
            }

            return(result);
        }
示例#5
0
 public CSVRow(CSVData i_Source, string[] i_Values, int i_Index)
 {
     Source = i_Source;
     Values = i_Values;
     Index  = i_Index;
 }
示例#6
0
 public CSVDataEnumerator(CSVData data)
 {
     m_Data  = data;
     m_Index = -1;
 }