C# - 读取字符串集合中的特定行 [英] C# - Reading a Specific line in a string collection

查看:122
本文介绍了C# - 读取字符串集合中的特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是真的不知道怎么回事,这是我的一半尝试,它实际上是不行的



I don''t don''t really know how, this is my half attempt on it, its oboiusly doesn''t work

int addnumber = 0;
       while (addnumber < Properties.Settings.Default.DatesEventNames.Count)
       {
           addnumber = addnumber + 1;
               DateTime yourDateTime = DateTime.ParseExact(item, "ddMMyyyy", CultureInfo.InvariantCulture);
       }





假设我有一个字符串集合中含有此字符串





Lets say I have a string collection with this in it

hi<br />
hi2<br />
hi3<br />
hi4





我只是想在我的文本框中看到h3,而不是所有这些,我希望能够通过行号读取行不是





and i just want to see h3 in my textbox, and not really all of them, I want to be able to read the line by the line number not

if(stringcollection.contains(h3)
{
}





所以我不想要包含字符串的方法,我想要的方法有点像





so I dont want the contains string method, I want the method that it kinda like

In (stringcollection.linenumber == 3)
{
textbox.text = the string's text on that line number
}

< br $> b $ b



这将是hi3。任何人都可以帮我解决这个问题吗?




and that would be "hi3". can anyone please help me out with this?

推荐答案

你有一个集合,你可以通过索引访问它。 myStringCollection [3]。此外,如果您想使用非连续索引来访问项目,您可以使用字典
You have a collection, you can access it by index. myStringCollection[3]. Also, you can use a dictionary if you want to use a non sequential index to access an item


Hi Tech,

i刚刚为您提供了样本帮助。 ...可能它可以帮助你



Hi Tech,
i just made a sample for your help....may be it can help u

ArrayList list = new ArrayList();
       list.Add("hi1");
       list.Add("hi2");
       list.Add("hi3");
       foreach (string item in list)
       {

           int index=item.LastIndexOf('3');
           if (index==2)//**also u can use (index>1)
               Response.Write("hi3");
       }


这篇关于C# - 读取字符串集合中的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆