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


C# CsvReader.GetFieldIndex方法代码示例

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


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

示例1: CheckSampleData1

		public static void CheckSampleData1(CsvReader csv, bool readToEnd)
		{
			if (readToEnd)
			{
				Assert.AreEqual(CsvReaderSampleData.SampleData1FieldCount, csv.FieldCount);

				if (csv.HasHeaders)
				{
					Assert.AreEqual(0, csv.GetFieldIndex(SampleData1Header0));
					Assert.AreEqual(1, csv.GetFieldIndex(SampleData1Header1));
					Assert.AreEqual(2, csv.GetFieldIndex(SampleData1Header2));
					Assert.AreEqual(3, csv.GetFieldIndex(SampleData1Header3));
					Assert.AreEqual(4, csv.GetFieldIndex(SampleData1Header4));
					Assert.AreEqual(5, csv.GetFieldIndex(SampleData1Header5));
				}
				
				Assert.AreEqual(-1, csv.CurrentRecordIndex);

				int recordCount = 0;

				while (csv.ReadNextRecord())
				{
					CheckSampleData1(csv.CurrentRecordIndex, csv);
					recordCount++;
				}

				if (csv.HasHeaders)
					Assert.AreEqual(CsvReaderSampleData.SampleData1RecordCount, recordCount);
				else
					Assert.AreEqual(CsvReaderSampleData.SampleData1RecordCount + 1, recordCount);
			}
			else
				CheckSampleData1(csv.CurrentRecordIndex, csv);
		}
开发者ID:jhgbrt,项目名称:netcsv,代码行数:34,代码来源:CsvReaderSampleData.cs

示例2: ParseData

        public bool ParseData(string filename)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(filename), true))
            {
                int fieldCount = csv.FieldCount;

                int rollFieldIndex = csv.GetFieldIndex("Roll Input (ratio)");
                int pitchFieldIndex = csv.GetFieldIndex("Pitch Input (ratio)");
                int yawFieldIndex = csv.GetFieldIndex("Yaw Input (ratio)");

                if (rollFieldIndex == -1 || pitchFieldIndex == -1 || yawFieldIndex == -1)
                {
                    return false;
                }

                int currentIndex = 0;

                while (csv.ReadNextRecord() && currentIndex < n_fileRowCount)
                {
                    f_timeInputArray[currentIndex] = float.Parse(csv[0]);
                    f_rollInputArray[currentIndex] = float.Parse(csv[rollFieldIndex]);
                    f_pitchInputArray[currentIndex] = float.Parse(csv[pitchFieldIndex]);
                    f_yawInputArray[currentIndex] = float.Parse(csv[yawFieldIndex]);
                    f_maxTime = f_timeInputArray[currentIndex];
                    currentIndex++;
                }
                f_startTime = f_timeInputArray[0];
                n_dataPoints = currentIndex;
            }

            return true;
        }
开发者ID:jplumpto,项目名称:KatanaSimTools-V2012,代码行数:32,代码来源:FlightTestData.cs

示例3: GetGitIssuesFromTracTsv

 private static IEnumerable<GitIssue> GetGitIssuesFromTracTsv(GitRepos repos)
 {
     var req = WebRequest.Create(tracTsvUrl);
     var res = req.GetResponse() as HttpWebResponse;
     if (res == null)
     {
         throw new ApplicationException("Could not load trac tsv issues from "+tracTsvUrl);
     }
     if (res.StatusCode!=HttpStatusCode.OK)
     {
         throw new ArgumentException(String.Format(
             "Could not load trac tsv issues from {0}: Status code {1} - {2}",
             tracTsvUrl,
             res.StatusCode,
             res.StatusDescription));
     }
     var tsvStream = res.GetResponseStream();
     if (tsvStream == null) return new GitIssue[0];
     var reader = new CsvReader(new StreamReader(tsvStream), true, '\t', '"', '"', '#', ValueTrimmingOptions.All) {SupportsMultiline = true};
     var fieldHeaders = reader.GetFieldHeaders().ToList();
     if (fieldHeaders.Count == 0) return new GitIssue[0];
     int issueIndex = reader.GetFieldIndex("ticket");
     int summaryIndex = reader.GetFieldIndex("summary");
     int descriptionIndex = reader.GetFieldIndex("_description");
     int statusIndex = reader.GetFieldIndex("status");
     var labelFieldIndexes =
         new string[] {"type", "component", "version", "severity", "priority"}
             .Select(reader.GetFieldIndex)
             .Where(i => i > -1)
             .ToList();
     var gitIssues = new List<GitIssue>();
     var labels = repos.Labels;
     while (reader.ReadNextRecord())
     {
         var i = new GitIssue(repos)
                     {
                         Title = (summaryIndex > -1) ? reader[summaryIndex] : "",
                         IsOpen = true,
                         Body = ((descriptionIndex > -1) ? reader[descriptionIndex] : "").Replace("\r", "").TrimEnd(new[] {'\n', ' ', '\t'})
                     };
         if (issueIndex > -1)
         {
             int no;
             if (Int32.TryParse(reader[issueIndex], out no))
             {
                 i.Number = no;
             }
             i.Body += "\n\nTrac issue " + reader[issueIndex];
         }
         if (statusIndex > 0)
         {
             if (reader[statusIndex]=="closed") i.IsOpen = false;
         }
         foreach (var label in labels.Where(l => labelFieldIndexes.Any(index => l.Name == reader[index]))) i.Labels.Add(label);
         gitIssues.Add(i);
     }
     return gitIssues.OrderBy(i => i.Number);
 }
开发者ID:oleholstandersen,项目名称:GitScrum,代码行数:58,代码来源:Program.cs

示例4: FindColumn

 private static string FindColumn(CsvReader csv, string col)
 {
     var i = csv.GetFieldIndex(col);
     if (i >= 0)
         return csv[i];
     return null;
 }
开发者ID:stevesloka,项目名称:bvcms,代码行数:7,代码来源:FindTagPeople.cs

示例5: DoUpdate

        private void DoUpdate(string text)
        {
            csv = new CsvReader(new StringReader(text), true, '\t');
            if(csv.GetFieldIndex("OrganizationId") == -1)
                throw new UserInputException("Missing required OrganizationId column");
            while (csv.ReadNextRecord())
            {
                var oid = csv["OrganizationId"].ToInt();
                var o = DbUtil.Db.LoadOrganizationById(oid);
                rs = DbUtil.Db.CreateRegistrationSettings(oid);

                var name = FindColumn("OrganizationName");
                if (name.HasValue())
                    o.OrganizationName = name;

                UpdateAsk("AskAllergies");
                UpdateAsk("AnswersNotRequired");
                UpdateAsk("AskChurch");
                UpdateAsk("AskCoaching");
                UpdateAsk("AskDoctor");
                UpdateAsk("AnswersNotRequired");
                UpdateAsk("AskChurch");
                UpdateAsk("AskCoaching");
                UpdateAsk("AskDoctor");
                UpdateAsk("AskEmContact");
                UpdateAsk("AskInsurance");
                UpdateAsk("AskParents");
                UpdateAsk("AskSMS");
                UpdateAsk("AskTylenolEtc");
                UpdateAsk("AskSuggestedFee");
                UpdateAskLabel("AskRequest");
                UpdateAskLabel("AskTickets");

                var b = FindColumn("NoReqBirthYear").ToBool2();
                if (b.HasValue)
                    rs.NoReqBirthYear = b.Value;
                b = FindColumn("NotReqDOB").ToBool2();
                if (b.HasValue)
                    rs.NotReqDOB = b.Value;
                b = FindColumn("NotReqAddr").ToBool2();
                if (b.HasValue)
                    rs.NotReqAddr = b.Value;
                b = FindColumn("NotReqGender").ToBool2();
                if (b.HasValue)
                    rs.NotReqGender = b.Value;
                b = FindColumn("NotReqMarital").ToBool2();
                if (b.HasValue)
                    rs.NotReqMarital = b.Value;
                b = FindColumn("NotReqPhone").ToBool2();
                if (b.HasValue)
                    rs.NotReqPhone = b.Value;
                b = FindColumn("NotReqZip").ToBool2();
                if (b.HasValue)
                    rs.NotReqZip = b.Value;

                b = FindColumn("AllowOnlyOne").ToBool2();
                if (b.HasValue)
                    rs.AllowOnlyOne = b.Value;
                b = FindColumn("MemberOnly").ToBool2();
                if (b.HasValue)
                    rs.MemberOnly = b.Value;
                b = FindColumn("AddAsProspect").ToBool2();
                if (b.HasValue)
                    rs.AddAsProspect = b.Value;
                b = FindColumn("TargetExtraValues").ToBool2();
                if (b.HasValue)
                    rs.TargetExtraValues = b.Value;
                b = FindColumn("AllowReRegister").ToBool2();
                if (b.HasValue)
                    rs.AllowReRegister = b.Value;
                b = FindColumn("AllowSaveProgress").ToBool2();
                if (b.HasValue)
                    rs.AllowSaveProgress = b.Value;
                b = FindColumn("DisallowAnonymous").ToBool2();
                if (b.HasValue)
                    rs.DisallowAnonymous = b.Value;
                b = FindColumn("ApplyMaxToOtheFees").ToBool2();
                if (b.HasValue)
                    rs.ApplyMaxToOtherFees = b.Value;
                b = FindColumn("IncludeOtherFeesWithDeposit").ToBool2();
                if (b.HasValue)
                    rs.IncludeOtherFeesWithDeposit = b.Value;
                b = FindColumn("OtherFeesAddedToOrgFee").ToBool2();
                if (b.HasValue)
                    rs.OtherFeesAddedToOrgFee = b.Value;
                b = FindColumn("AskDonation").ToBool2();
                if (b.HasValue)
                    rs.AskDonation = b.Value;

                var s = FindColumn("ConfirmationTrackingCode");
                rs.ConfirmationTrackingCode = s;

                s = FindColumn("ValidateOrgs");
                rs.ValidateOrgs = s;

                s = FindColumn("Shell");
                rs.Shell = s;

                s = FindColumn("ShellBs");
                rs.ShellBs = s;
//.........这里部分代码省略.........
开发者ID:vanutama,项目名称:bvcms,代码行数:101,代码来源:BatchRegOptions.cs

示例6: GetFieldHeadersTest2

        public void GetFieldHeadersTest2()
        {
            using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), true))
            {
                string[] headers = csv.GetFieldHeaders();

                Assert.IsNotNull(headers);
                Assert.AreEqual(CsvReaderSampleData.SampleData1RecordCount, headers.Length);

                Assert.AreEqual(CsvReaderSampleData.SampleData1Header0, headers[0]);
                Assert.AreEqual(CsvReaderSampleData.SampleData1Header1, headers[1]);
                Assert.AreEqual(CsvReaderSampleData.SampleData1Header2, headers[2]);
                Assert.AreEqual(CsvReaderSampleData.SampleData1Header3, headers[3]);
                Assert.AreEqual(CsvReaderSampleData.SampleData1Header4, headers[4]);
                Assert.AreEqual(CsvReaderSampleData.SampleData1Header5, headers[5]);

                Assert.AreEqual(0, csv.GetFieldIndex(CsvReaderSampleData.SampleData1Header0));
                Assert.AreEqual(1, csv.GetFieldIndex(CsvReaderSampleData.SampleData1Header1));
                Assert.AreEqual(2, csv.GetFieldIndex(CsvReaderSampleData.SampleData1Header2));
                Assert.AreEqual(3, csv.GetFieldIndex(CsvReaderSampleData.SampleData1Header3));
                Assert.AreEqual(4, csv.GetFieldIndex(CsvReaderSampleData.SampleData1Header4));
                Assert.AreEqual(5, csv.GetFieldIndex(CsvReaderSampleData.SampleData1Header5));
            }
        }
开发者ID:jboolean,项目名称:RIT-Bus,代码行数:24,代码来源:CsvReaderTest.cs

示例7: WritePeptides

        private void WritePeptides(Dictionary<string, ExperimentGroup> expgroups, string outputDirectory)
        {
            foreach (Peptide pep in Peptides.Values)
            {
                if (pep.ProteinGroups == null || pep.ProteinGroups.Count < 1) continue;
                pep.ProteinGroups.Sort(ProteinGroup.CompareIncreasing);
                pep.BestPG = pep.ProteinGroups[0];
            }
            // Loop over each experiment
            foreach (ExperimentGroup exp in expgroups.Values)
            {
                string experimentName = exp.Name;
                List<CsvFile> files = exp.CsvFiles;
                StreamWriter writer = null;
                if (IncludeNonFilteredResults)
                {
                    string filename = "";
                    if (string.IsNullOrEmpty(experimentName))
                    {
                        filename = Path.Combine(outputDirectory, "Parsimony_peptides.csv");
                    }
                    else
                    {
                        filename = Path.Combine(outputDirectory, string.Format("{0}_parsimony_peptides.csv", experimentName));
                    }
                    Log("Writing file {0}", filename);
                    writer = new StreamWriter(filename);
                }
                string filteredfilename = "";
                if (string.IsNullOrEmpty(experimentName))
                {
                    filteredfilename = Path.Combine(outputDirectory, "Parsimony_peptides_filtered.csv");
                }
                else
                {
                    filteredfilename = Path.Combine(outputDirectory, string.Format("{0}_parsimony_peptides_filtered.csv", experimentName));
                }
                Log("Writing file {0}", filteredfilename);
                StreamWriter filteredwriter = new StreamWriter(filteredfilename);

                string header = exp.Header + ",Experiment Name,# of Sharing PGs,Best PG Name";
                if (IncludeNonFilteredResults)
                {
                    writer.WriteLine(header);
                }
                filteredwriter.WriteLine(header);

                foreach (CsvFile csvfile in files)
                {
                    string sequenceString = "Peptide";
                    //string spectrumNumberString = "Spectrum number";
                    //string pvalueString = "P-value";

                    // Open up the csvfile and read it's contents, skipping the header
                    using (CsvReader reader = new CsvReader(new StreamReader(csvfile.FilePath), true))
                    {
                        bool pdOutput = false;
                        if (reader.GetFieldHeaders().Contains("XCorr"))
                        {
                            sequenceString = "Sequence";
                            //spectrumNumberString = "RT [min]";
                            //pvalueString = "PEP";
                            pdOutput = true;
                        }

                        int deflineIndex = reader.GetFieldIndex("Defline");
                        int modIndex = reader.GetFieldIndex("Mods");
                        int startRes = reader.GetFieldIndex("Start");
                        int stopRes = reader.GetFieldIndex("Stop");
                        Peptide pep = null;
                        // Read in each psm
                        while (reader.ReadNextRecord())
                        {
                            string seq = reader[sequenceString].ToUpper();
                            string leuSeq = seq.Replace('I', 'L');

                            string[] data = new string[reader.FieldCount];
                            if (Peptides.TryGetValue(leuSeq, out pep))
                            {
                                if (pep.BestPG == null || pep.BestPG.IsDecoy) continue;

                                foreach (ProteinGroup pg in pep.ProteinGroups)
                                {
                                    exp.ProteinGroups.Add(pg);
                                    int psms = 0;
                                    if (pg.PsmsPerGroup.TryGetValue(exp, out psms))
                                    {
                                        psms++;
                                        pg.PsmsPerGroup[exp] = psms;
                                    }
                                    else
                                    {
                                        pg.PsmsPerGroup.Add(exp, 1);
                                    }
                                    HashSet<Peptide> peptides = null;
                                    if (pg.UniquePeptidesPerGroup.TryGetValue(exp, out peptides))
                                    {
                                        peptides.Add(pep);
                                    }
                                    else
//.........这里部分代码省略.........
开发者ID:dbaileychess,项目名称:Compass,代码行数:101,代码来源:ProteinHoarder.cs


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