当前位置: 首页>>代码示例>>C#>>正文


C# TextFieldParser.Close方法代码示例

本文整理汇总了C#中Microsoft.VisualBasic.FileIO.TextFieldParser.Close方法的典型用法代码示例。如果您正苦于以下问题:C# TextFieldParser.Close方法的具体用法?C# TextFieldParser.Close怎么用?C# TextFieldParser.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.VisualBasic.FileIO.TextFieldParser的用法示例。


在下文中一共展示了TextFieldParser.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProviderMgr

        public ProviderMgr()
        {
            TextFieldParser parser = new TextFieldParser(@"" + Directory.GetCurrentDirectory() + "\\dnscrypt-resolvers.csv");
            parser.TextFieldType = FieldType.Delimited;
            parser.SetDelimiters(",");

            while (!parser.EndOfData)
            {
                ProviderItem providerItem = new ProviderItem();

                string[] fields = parser.ReadFields();

                providerItem.setName(fields[0]);
                providerItem.setFullName(fields[1]);
                providerItem.setDescription(fields[2]);
                providerItem.setLocation(fields[3]);
                providerItem.setCoordinates(fields[4]);
                providerItem.setURL(fields[5]);
                providerItem.setVersion(fields[6]);
                providerItem.setDNSSEC(fields[7]);
                providerItem.setNoLogs(fields[8]);
                providerItem.setNamecoin(fields[9]);
                providerItem.setAddress(fields[10]);
                providerItem.setProviderName(fields[11]);
                providerItem.setPublicKey(fields[12]);
                providerItem.setPublicKeyTXT(fields[13]);
                providerList.Add(providerItem);
            }
            parser.Close();

            // Remove first line from CVS (Name, etc, etc)
            providerList.RemoveAt(0);
        }
开发者ID:Davescott290,项目名称:dnscrypt-winservicemgr,代码行数:33,代码来源:ProviderMgr.cs

示例2: ReportFile

        public ReportFile(string path)
        {
            fileInfo = new FileInfo(path);

            if (!fileInfo.Exists)
            {
                CreateReportFile(fileInfo);
            }

            var parser = new TextFieldParser(path) { Delimiters = new[] { "," } };

            if (!parser.EndOfData)
            {
                var headerFields = parser.ReadFields();
                var langList = new List<string>();

                // skip Date/Time and Word Count column headers
                for (var i = 2; i < headerFields.Length; ++i)
                {
                    var lang = headerFields[i];

                    langList.Add(lang);
                    langs.Add(lang);
                }

                while (!parser.EndOfData)
                {
                    rows.Add(new ReportRow(langList.ToArray(), parser.ReadFields()));
                }
            }

            parser.Close();
        }
开发者ID:Art1stical,项目名称:AHRUnrealEngine,代码行数:33,代码来源:ReportFile.cs

示例3: ImportCSV

        public static void ImportCSV(string file)
        {
            TextFieldParser parser = new TextFieldParser(file);
            parser.TextFieldType = FieldType.Delimited;
            parser.SetDelimiters(",");
            Boolean header = true;
            while (!parser.EndOfData)
            {
                // We don't want to import the header row
                if (header)
                {
                    header = false;
                    parser.ReadFields();
                    continue;
                }

                // Vars
                DateTime dt;
                DateTime dt2 = Convert.ToDateTime("4/15/2010");
                Boolean error = false;
                string[] fields = parser.ReadFields();

                // Check for error conditions
                if (String.IsNullOrEmpty(fields[3]))
                {
                    // Score is null
                    fields[3] = "0";
                    error = true;
                }
                if (!DateTime.TryParse(fields[2], out dt))
                {
                    // Date is invalid
                    fields[2] = "05/05/55";
                    error = true;
                }
                if (dt > dt2)
                {
                    // Date is > 4/15/2010
                    error = true;
                }

                // Insert into the correct table
                if (error)
                {
                    InsertError(fields[0], fields[1], fields[2], fields[3]);
                }
                else
                {
                    Insert(fields[0], fields[1], fields[2], fields[3]);
                }
            }
            parser.Close();
        }
开发者ID:vgck,项目名称:archive,代码行数:53,代码来源:Program.cs

示例4: parsecsv

        public List<string[]> parsecsv(string path)
        {
            List<string[]> parsedData = new List<string[]>();
            string[] fields;

            try
            {
                //TODO add check to see if the csv file is a valid one or validate data in each field
                TextFieldParser parser = new TextFieldParser(path);
                parser.TextFieldType = FieldType.Delimited;
                parser.SetDelimiters(",");
                parser.TrimWhiteSpace = true;//trims white space from the strings
                int numExcludedRows = 0;

                while (!parser.EndOfData)
                {
                    fields = parser.ReadFields();

                    //check to see if the row has any blank fields
                    if (fields.Contains(""))
                    {
                        //do nothing with the string
                        numExcludedRows++;
                    }
                    else //the string doesn't include blank fields
                    {
                                parsedData.Add(fields);
                    }
                }

                if (numExcludedRows > 0)
                {
                    MessageBox.Show("Some rows were incomplete, removed data for " + numExcludedRows.ToString() + " ties.", "SkyRise Canopy Creator");
                }

                //remove the headers from the List
                if (parsedData.Count() >= 2)
                {
                    parsedData.RemoveAt(0);
                }

                //close the reader
                parser.Close();

            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            return parsedData;
        }
开发者ID:kdaner,项目名称:04_ProjSpecificPanel_SkyRise-Canopy-Creator,代码行数:52,代码来源:CsvParser.cs

示例5: ProcessFile

        public void ProcessFile()
        {
            TextFieldParser tfp = new TextFieldParser(this.Filename);
            tfp.HasFieldsEnclosedInQuotes = true;
            tfp.Delimiters = new string[] { ",", "\t" };
            string[] line;

            while (!tfp.EndOfData)
            {
                line = tfp.ReadFields();
                mLines.Add(line);
            }
            tfp.Close();
        }
开发者ID:tempbottle,项目名称:INCC6,代码行数:14,代码来源:CSVFile.cs

示例6: AnimationData

        static AnimationData()
        {
            Fallback = new Dictionary<ushort, ushort>();
            NameToId = new Dictionary<string, ushort>();
            IdToName = new Dictionary<ushort, string>();
            PlayThenStop = new HashSet<ushort>();
            PlayBackwards = new HashSet<ushort>();
            var assembly = Assembly.GetExecutingAssembly();
            var embeddedStream = assembly.GetManifestResourceStream("M2Lib.src.csv.AnimationData.csv");
            Debug.Assert(embeddedStream != null, "Could not open embedded ressource AnimationData");
            var csvParser = new TextFieldParser(embeddedStream) {CommentTokens = new[] {"#"}};
            csvParser.SetDelimiters(",");
            csvParser.HasFieldsEnclosedInQuotes = true;
            csvParser.ReadLine(); // Skip first line
            while (!csvParser.EndOfData)
            {
                var fields = csvParser.ReadFields();
                Debug.Assert(fields != null);
                var id = Convert.ToUInt16(fields[0]);
                var name = fields[1];
                var fallback = Convert.ToUInt16(fields[3]);
                Fallback[id] = fallback;
                NameToId[name] = id;
                IdToName[id] = name;
            }
            csvParser.Close();
            ushort[] playThenStopValues =
            {
                NameToId["Dead"],
                NameToId["SitGround"],
                NameToId["Sleep"],
                NameToId["KneelLoop"],
                NameToId["UseStandingLoop"],
                NameToId["Drowned"],
                NameToId["LootHold"]
            };
            foreach (var value in playThenStopValues) PlayThenStop.Add(value);
            ushort[] playBackwardsValues =
            {
                NameToId["Walkbackwards"],
                NameToId["SwimBackwards"],
                NameToId["SleepUp"],
                NameToId["LootUp"]
            };
            foreach (var value in playBackwardsValues) PlayBackwards.Add(value);

            //TODO FIXME There a loops by following the fallbacks in AnimationData.dbc. Happens with Close and FlyClose.
            Fallback[146] = 0;//Close
            Fallback[375] = 0;//FlyClose
        }
开发者ID:Koward,项目名称:M2Lib,代码行数:50,代码来源:AnimationData.cs

示例7: Read

        public static int Read(String fileName)
        {
            var result = new List<String[]>();
            TextFieldParser parser = null;

            try
            {
                parser = new TextFieldParser(fileName, System.Text.Encoding.UTF8);
                parser.SetDelimiters(new[] { "," });

                while (!parser.EndOfData)
                {
                    // TODO CRLFで複数行に分割され、空行が存在する場合に対応できず
                    var fields = parser.ReadFields();

                    // TODO カラム数のチェック

                    Debug.WriteLine("----------------------");
                    foreach (var item in fields.ToList())
                    {
                        Debug.Write(item);
                        Debug.WriteLine("**");
                    }
                }
            }
            catch (System.IO.FileNotFoundException ex)
            {
            }
            catch (MalformedLineException ex)
            {
                // 解析不能例外
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (parser != null)
                {
                    parser.Close();
                }
            }

            return 0;
        }
开发者ID:narareimei,项目名称:CSharp,代码行数:46,代码来源:CSVReader.cs

示例8: ReadCsv

        /// <summary>
        /// CSVファイルを読み込みます
        /// </summary>
        /// <param name="csvFileName">
        /// CSVパス
        /// </param>
        /// <returns>
        /// CSVファイル内の行データの配列
        /// </returns>
        /// <exception cref="ApplicationException">
        /// </exception>
        public static IEnumerable<IEnumerable<string>> ReadCsv(string csvFileName)
        {
            var csvRecords = new List<IEnumerable<string>>();

            // Shift JISで読み込む
            var tfp = new TextFieldParser(
                csvFileName,
                System.Text.Encoding.GetEncoding(932))
            {
                TextFieldType = FieldType.Delimited,
                Delimiters = new[] {","},
                HasFieldsEnclosedInQuotes = true,
                TrimWhiteSpace = true
            };

            // フィールドが文字で区切られているとする
            // デフォルトでDelimitedなので、必要なし
            // 区切り文字を,とする
            // フィールドを"で囲み、改行文字、区切り文字を含めることができるか
            // デフォルトでtrueなので、必要なし
            // フィールドの前後からスペースを削除する
            // デフォルトでtrueなので、必要なし
            try
            {
                while (!tfp.EndOfData)
                {
                    // フィールドを読み込む
                    var fields = tfp.ReadFields();

                    // 保存
                    csvRecords.Add(fields);
                }
            }
            catch (MalformedLineException ex)
            {
                throw new ApplicationException("Line " + ex.Message + " is invalid.  Skipping");
            }
            finally
            {
                // 後始末
                tfp.Close();
            }

            return csvRecords;
        }
开发者ID:masahiro-nakatani,项目名称:robocon,代码行数:56,代码来源:CsvAdaptor.cs

示例9: Main

        static void Main(string[] args)
        {
            TextFieldParser csvG = new TextFieldParser(@"E:\Stocks\Archive\AAPL.csv");
            csvG.TextFieldType = FieldType.Delimited;
            // set delimiter
            csvG.SetDelimiters("/r/n");

            while (!csvG.EndOfData)
            {
                string[] fields = csvG.ReadFields();
                foreach (string field in fields)
                {
                    Console.WriteLine(field);
                }
            }
            csvG.Close();
            Console.ReadLine();
        }
开发者ID:tmmtsmith,项目名称:CSharpDOTNET,代码行数:18,代码来源:csv.cs

示例10: Orders

        public static IEnumerable<Order> Orders()
        {
            TextFieldParser parser = new TextFieldParser(@"order_data.csv");
            parser.TextFieldType = FieldType.Delimited;
            parser.SetDelimiters(",");

            while (!parser.EndOfData)
            {
                //Processing row
                string[] fields = parser.ReadFields();
                yield return new Order(productMap[fields[0]],
                                       traderMap[fields[1]],
                                       fields[2] == "0" ? OrderSide.Buy : OrderSide.Sell,
                                       decimal.Parse(fields[3]),
                                       decimal.Parse(fields[4]));
            }
            parser.Close();
        }
开发者ID:smies,项目名称:bitPrice,代码行数:18,代码来源:TestData.cs

示例11: readData

        /// <summary>
        /// Reading in the data from the csv file
        /// </summary>
        public static void readData()
        {
            //==========================================
            //      Reading in the cemetery data
            //==========================================
            TextFieldParser parser = new TextFieldParser(@"data3.csv");
            parser.TextFieldType = FieldType.Delimited;
            parser.SetDelimiters(",");
            int i = 0;

            //Looping through each line
            while (!parser.EndOfData) {

                //Reading the line
                string[] fields = parser.ReadFields();

                //Skipping the first and second row
                i++; if (i == 1 || i == 2) continue;

                //Creating a new cemetery object
                cemetery c = new cemetery();
                c.cemetery_id = int.Parse(fields[0]);
                c.name = fields[1];
                c.lat = float.Parse(fields[2]);
                c.lon = float.Parse(fields[3]);
                c.city = fields[4];
                c.state = fields[5];
                c.country = fields[6];

                //Reading in the temperature data
                List<double> temps = new List<double>();
                int j = 0;
                foreach (string f in fields) {
                    j++; if (j <= 7) continue;
                    temps.Add(double.Parse(f));
                }
                c.temps = temps;

                //Adding the cemetery to the list
                cems.Add(c.cemetery_id, c);
                cemsList.Add(c);
            }

            //Closing the parser
            parser.Close();
        }
开发者ID:jeffnuss,项目名称:genetic-algorithm,代码行数:49,代码来源:Program.cs

示例12: isFileValid

        private bool isFileValid(string fileName, out List<string> errors)
        {
            //var reader = new StreamReader(File.OpenRead(fileName));
            var reader = new TextFieldParser(fileName);
            reader.TextFieldType = FieldType.Delimited;
            reader.SetDelimiters(GlobalConst.IMPORT_FILE_DELIMITER);

            int columnCount = 0;
            int rowCount = 0;
            bool fileValid = true;
            errors = new List<string>();
            try
            {
                while (!reader.EndOfData)
                {
                    string[] values = reader.ReadFields();

                    //Check file valid
                    if (rowCount > 1 && columnCount != values.Length)
                    {
                        fileValid = false;
                        errors.Add(String.Format("Found an inconsistent column length in file at line {0}.", rowCount));
                        reader.Close();
                        return fileValid;
                    }
                    columnCount = values.Length;
                    rowCount++;
                }
            }
            catch (Exception ex) { throw ex; }
            finally { reader.Close(); }

            return fileValid;
        }
开发者ID:CarlosLCervantes,项目名称:MusubiMailer,代码行数:34,代码来源:Import.xaml.cs

示例13: Parse

 static IEnumerable<ProcessMonitorEntry> Parse(string path, bool header = true)
 {
     var parser = new TextFieldParser(path);
     parser.TextFieldType = FieldType.Delimited;
     parser.SetDelimiters(",");
     if (header)
     {
         parser.ReadLine();
     }
     while (!parser.EndOfData)
     {
         var fields = parser.ReadFields();
         yield return new ProcessMonitorEntry
         {
             //TimeOfDay = fields[0],
             //ProcessName = fields[1],
             //PID = fields[2],
             //Operation = fields[3],
             Path = fields[4],
             Result = fields[5],
             //Details = fields[6]
         };
     }
     parser.Close();
 }
开发者ID:ahmelsayed,项目名称:VCExtract,代码行数:25,代码来源:Program.cs

示例14: Upload

        public ActionResult Upload(int? id)
        {
            Ingredient ingredient = new Ingredient();

            TextFieldParser parser = new TextFieldParser(@"C:\Users\Nicholas\Documents\Visual Studio 2015\Projects\Ingredients\test.csv");
            parser.TextFieldType = FieldType.Delimited;
            parser.SetDelimiters(",");
            while (!parser.EndOfData)
            {
                //Process row
                string[] fields = parser.ReadFields();

                ingredient.Name = fields[0];
                ingredient.Quantity = Convert.ToDecimal (fields[1]);
                ingredient.Units = fields[2];
                ingredient.Sku = fields[3];
                ingredient.Supplier = fields[4];

                if (ModelState.IsValid)
                {
                    db.Ingredients.Add(ingredient);
                    db.SaveChanges();

                }
            }
            parser.Close();

            return RedirectToAction("Index");
        }
开发者ID:khecharb,项目名称:Ingredients,代码行数:29,代码来源:IngredientsController.cs

示例15: LueCSVDataa

        // Käytetään VB Parseria CSV-datan lukemiseen koska meillä on "arvo;arvo" sarakkeita   
        private static List<string[]> LueCSVDataa(string tiedosto, char separator)
        {
            var csvData = new List<string[]>();

            try
            {
                TextFieldParser parser = new TextFieldParser(tiedosto);

                parser.HasFieldsEnclosedInQuotes = true;
                parser.SetDelimiters(";");

                string[] fields;

                while (!parser.EndOfData)
                {
                    fields = parser.ReadFields();
                    csvData.Add(fields);
                }
                parser.Close();               

            }
            catch (Exception e)
            {
                MessageBox.Show("Virhe csv-tiedostoa luettaessa: " + e.Message);              

            }

            return csvData;
        }
开发者ID:fredrikfinnberg,项目名称:CSVXMLOhjelma,代码行数:30,代码来源:CSCVirtaJulkaisutForm.cs


注:本文中的Microsoft.VisualBasic.FileIO.TextFieldParser.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。