我对C#中的数组列表有疑问
我有一个包含以下元素的数组:
- LQI Request
- 0123456
- LQI Request
- 456789
- LQI Request
- 6789
.....
现在我想做的就是找到LQI Request
的字符串,然后在它旁边找到字符串,这是我迄今为止所做的:(索引是全局的变量)
if(myString.Contains("LQI"))
{
index= stored_data.IndexOf(myString);
}
MessageBox.Show(index.ToString());
MessageBox.Show(stored_data[index+1].Tostring());
我运行此代码的时候,索引保持不变。它应该是:0,2,4
请帮忙
答案 0 :(得分:0)
下面的内容就是你所描述的。
static void Main(string[] args)
{
List<String> stored_data = new List<String>() { "LQI REquest","-0123456", "LQI Request", "-456789", "LQI Request", "-6789", "non valid", "12345", "extra", "12354" };
for (int j=0; j< stored_data.Count; j++)
{
if (stored_data[j].Contains("LQI"))
{
Console.Write((j).ToString()+ ": ");
var temp = j + 1;
Console.Write(stored_data[temp]);
Console.WriteLine();
}
}
Console.ReadLine();
}
答案 1 :(得分:0)
<div class="panel-body">
<div class="col-md-2" id="Active" onclick="activeCircleClick('tab1')">
<div id="active" style="height: 125px;">
//here is something
</div>
</div>
</div>
<div style="width:1300px;">
<div style="width:100%;">
<ul class="nav nav-tabs nav-pills nav-justified" role="tablist" id="myTab">
<li class="active" id="activeList">
<a href="#tab1" data-toggle="tab">Active device list</a>
<span class="col-md-12" id="activeDeviceStatus" style="text-align: center;"></span>
</li>
</ul>
</div>
<script>
function activeCircleClick(el)
{
alert("test1:" +el);
selectTab(el);
}
function selectTab(tabId)
{
alert('test2:' + tabId);
var tab = $("#" + tabId);
if (typeof tab != 'undefined')
{
e.preventDefault()
tab.tab('show');
}
}
</script>