Exemplo n.º 1
0
        private static string[][] getColumns(string fileName, int[] columnNumbers, char[] separators, int startLineIndex, StringSplitOptions stringSplitOptions)
        {
            string[][] values = FileInputOutputUtilities.LoadDelimitedFile(fileName, separators, splitOptions: stringSplitOptions);
            string[][] result = new string[columnNumbers.Length][];

            for (int col = 0; col < columnNumbers.Length; col++)
            {
                result[col] = new string[values.Length - startLineIndex];
                for (int i = startLineIndex; i < values.Length; i++)
                {
                    result[col][i - startLineIndex] = values[i][columnNumbers[col] - 1];
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public static Dictionary <string, string> LoadDictionary(string fileName, char delimiter)
        {
            Dictionary <string, string> result = new Dictionary <string, string>( );

            string[][] content = FileInputOutputUtilities.LoadDelimitedFile(fileName, delimiter);
            for (int i = 0; i < content.Length; i++)
            {
                if (content[i].Length != 2)
                {
                    throw new Exception("Expected exactly 2 columns in file " + fileName + " , but line number " + (i + 1) + " has " + content[i].Length);
                }
                if (result.ContainsKey(content[i][0]))
                {
                    throw new Exception("File " + fileName + ": found duplicate key '" + content[i][0] + "'");
                }
                result.Add(content[i][0], content[i][1]);
            }
            return(result);
        }
Exemplo n.º 3
0
 public static string[][] LoadFromCommaSeparated(string fileName)
 {
     return(FileInputOutputUtilities.LoadDelimitedFile(fileName, COMMA_CHARACTER));
 }