2017-08-03 45 views
0

我正在搜索一個數組並試圖查找對象描述。我遇到的問題是試圖使用通配符。我如何在數組中搜索以「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

'b.Contains( 「說明」)' – Gusman

+1

或'b.StartsWith( 「描述:」)' –

回答

4

你可能只是做:

Description = textlist.Where(s => s.StartsWith("Description:")).ToArray(); 
2
int[] poss = textlist.Select((b, i) => 
    b.StartsWith("Description") ? i : -1).Where(i => i != -1).ToArray(); 
相關問題