2017-08-03 4 views
0

Je suis à la recherche d'un tableau et j'essaie de trouver des descriptions d'objets. Le problème que j'ai est d'essayer d'utiliser un caractère générique. Comment puis-je rechercher dans ma matrice les valeurs commençant par "Description:".Comment rechercher une chaîne commençant par une certaine valeur?

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 ("Description")' ' – Gusman

+1

ou b.StartsWith ("Description:")' –

Répondre

4

Vous pouvez simplement faire:

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();