我正在搜索数组并尝试查找对象描述。我遇到的问题是尝试使用通配符。如何在数组中搜索以“Description:”开头的值。
int[] poss = textlist.Select((b, i) => b == "Description:*" ? i : -1).Where(i => i != -1).ToArray();
string[] Description = new string[poss.Length - 1];
foreach (int pos in poss)
{
Description = textlist[pos];
}
答案 0 :(得分:4)
你可以这样做:
Description = textlist.Where(s => s.StartsWith("Description:")).ToArray();
答案 1 :(得分:2)
int[] poss = textlist.Select((b, i) =>
b.StartsWith("Description") ? i : -1).Where(i => i != -1).ToArray();