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


C# CsvRow.RemoveAt方法代码示例

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


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

示例1: ReadRow

        /// <summary>
        /// Reads a row of data from a CSV file
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public bool ReadRow(CsvRow row)
        {
            row.LineText = ReadLine();
            if (String.IsNullOrEmpty(row.LineText))
                return false;

            int pos = 0;
            int rows = 0;

            while (pos < row.LineText.Length)
            {
                string value;

                // Parse unquoted value
                int start = pos;
                while (pos < row.LineText.Length && row.LineText[pos] != ',')
                    pos++;
                value = row.LineText.Substring(start, pos - start);

                // Add field to list
                if (rows < row.Count)
                    row[rows] = value;
                else
                    row.Add(value);
                rows++;

                // Eat up to and including next comma
                while (pos < row.LineText.Length && row.LineText[pos] != ',')
                    pos++;
                if (pos < row.LineText.Length)
                    pos++;
            }
            // Delete any unused items
            while (row.Count > rows)
                row.RemoveAt(rows);

            // Return true if any columns read
            return (row.Count > 0);
        }
开发者ID:D4rkM4tter,项目名称:StoreOffice,代码行数:44,代码来源:CsvFileReader.cs

示例2: ReadRow

        /// <summary>
        /// Reads a row of data from a CSV file
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public bool ReadRow(CsvRow row)
        {
            row.LineText = ReadLine();
            if (String.IsNullOrEmpty(row.LineText))
                return false;

            int pos = 0;
            int rows = 0;

            while (pos < row.LineText.Length)
            {
                string value;

                // Special handling for quoted field
                if (row.LineText[pos] == '"')
                {
                    // Skip initial quote
                    pos++;

                    // Parse quoted value
                    int start = pos;
                    while (pos < row.LineText.Length)
                    {
                        // Test for quote character
                        if (row.LineText[pos] == '"')
                        {
                            // Found one
                            pos++;

                            // If two quotes together, keep one
                            // Otherwise, indicates end of value
                            if (pos >= row.LineText.Length || row.LineText[pos] != '"')
                            {
                                pos--;
                                break;
                            }
                        }
                        pos++;
                    }
                    value = row.LineText.Substring(start, pos - start);
                    value = value.Replace("\"\"", "\"");
                }
                else
                {
                    // Parse unquoted value
                    int start = pos;
                    while (pos < row.LineText.Length && row.LineText[pos] != ',')
                        pos++;
                    value = row.LineText.Substring(start, pos - start);
                }

                // Add field to list
                if (rows < row.Count)
                    row[rows] = value;
                else
                    row.Add(value);
                rows++;

                // Eat up to and including next comma
                while (pos < row.LineText.Length && row.LineText[pos] != ',')
                    pos++;
                if (pos < row.LineText.Length)
                    pos++;
            }
            // Delete any unused items
            while (row.Count > rows)
                row.RemoveAt(rows);

            // Return true if any columns read
            return (row.Count > 0);
        }
开发者ID:JamesPinkard,项目名称:HackerRankJpink,代码行数:76,代码来源:CsvFileReader.cs

示例3: WorkerProc

        public void WorkerProc()
        {
            _success = true; // all is good unless something fails
            _active = true;

            _client = new TranslateService.LanguageServiceClient();

            // Get the manually corrected values if they exist
            System.Collections.Generic.SortedList<string, string> translatedValues = new SortedList<string, string>(); // automatic translations
            System.Collections.Generic.SortedList<string, string> manualValues = new SortedList<string, string>(); // User translations

            string fixedLanguageFileName = Path.Combine(_localisationPath, _languageCode + "-fixed.txt");

            if (File.Exists(fixedLanguageFileName))
            {
                using (CsvFileReader reader = new CsvFileReader(fixedLanguageFileName))
                {
                    CsvRow row = new CsvRow();
                    while (reader.ReadRow(row))
                    {
                        if (row.Count > 1)
                        {
                            if (!manualValues.ContainsKey(row[0]))
                            {
                                manualValues.Add(row[0], row[1]); // Create a sorted list of values with manual updates
                            }
                        }
                    }
                }
            }

            // Create the language file
            string languageFileName = Path.Combine(_localisationPath, _languageCode + ".txt");

            // If the file already exists then don't overwrite it
            // So we don't overwrite from scratch. If new translations are required then the existing files needs to be deleted first
            // If the language file already exists then load the file so we can add new strings and deletes one not being used
            // BING now limits the amount of data that can be downloaded so we should only update what's required instead of downloading everthing again
            CsvRow orgRow = new CsvRow();
            if (File.Exists(languageFileName))
            {
                using (CsvFileReader orgReader = new CsvFileReader(languageFileName))
                {
                    while (orgReader.ReadRow(orgRow)) // Read all the data in
                    {
                        if (manualValues.ContainsKey(orgRow[0]))
                            _manual++; // We have a manual translation

                        if (!translatedValues.ContainsKey(orgRow[0]))
                            translatedValues.Add(orgRow[0], orgRow[1]); // Add to the sorted listed - we don't add manual translations here, just track them. They are added on the fly at runtime
                        else
                            _duplicate++; // Duplicate
                    }
                }
            }

            using (CsvFileWriter writer = new CsvFileWriter(languageFileName))
            {
                using (CsvFileReader reader = new CsvFileReader(_englishFilePath))
                {
                    CsvRow row = new CsvRow();
                    while (reader.ReadRow(row))
                    {
                        if (row.Count > 0)
                        {
                            while (row.Count > 1) row.RemoveAt(1);
                            string transText = "";
                            if (translatedValues.ContainsKey(row[0]))
                            {
                                transText = translatedValues[row[0]];
                                _replaced++;
                            }
                            else
                            {
                                transText = TranslateText(row[0], _languageCode);

                                // check for a null return, then BING failed due to quota issues
                                if (transText == null)
                                {
                                    _success = false; // break out and clean up the file
                                    break;
                                }
                                else
                                    _downloaded++;
                            }

                            row.Add(transText);
                            writer.WriteRow(row); // Write the data
                            _progress++;

                            if (_cancelled)
                            {
                                _success = false;
                                break;
                            }

                            if (Console.KeyAvailable) // check if any other thread caught the cancellation event (ESC)
                            {
                                ConsoleKeyInfo cki = Console.ReadKey(true);
                                if ((cki.Key == ConsoleKey.Escape) || ((cki.Modifiers == ConsoleModifiers.Control) && (cki.Key == ConsoleKey.C)))
//.........这里部分代码省略.........
开发者ID:hoeness2,项目名称:mcebuddy2,代码行数:101,代码来源:Translate.cs

示例4: ReadRow

 public bool ReadRow(CsvRow row)
 {
     row.LineText = this.ReadLine();
     bool result;
     if (string.IsNullOrEmpty(row.LineText))
     {
         result = false;
     }
     else
     {
         int i = 0;
         int num = 0;
         while (i < row.LineText.Length)
         {
             string text;
             if (row.LineText[i] == '"')
             {
                 i++;
                 int num2 = i;
                 while (i < row.LineText.Length)
                 {
                     if (row.LineText[i] == '"')
                     {
                         i++;
                         if (i >= row.LineText.Length || row.LineText[i] != '"')
                         {
                             i--;
                             break;
                         }
                     }
                     i++;
                 }
                 text = row.LineText.Substring(num2, i - num2);
                 text = text.Replace("\"\"", "\"");
             }
             else
             {
                 int num2 = i;
                 while (i < row.LineText.Length && row.LineText[i] != ',')
                 {
                     i++;
                 }
                 text = row.LineText.Substring(num2, i - num2);
             }
             if (num < row.Count)
             {
                 row[num] = text;
             }
             else
             {
                 row.Add(text);
             }
             num++;
             while (i < row.LineText.Length && row.LineText[i] != ',')
             {
                 i++;
             }
             if (i < row.LineText.Length)
             {
                 i++;
             }
         }
         while (row.Count > num)
         {
             row.RemoveAt(num);
         }
         result = (row.Count > 0);
     }
     return result;
 }
开发者ID:Padungsak,项目名称:efinTradePlus,代码行数:70,代码来源:CsvFileReader.cs


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