1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
string[] lignes = new string[]
{
"ceci est une ligne de test 01 05 69 70",
"ceci est une autre ligne de test 55 555 977 05 69 70"
};
foreach (var ligne in lignes)
{
string clef = string.Empty;
string nombre_s = string.Empty;
var split = ligne.Split(' ');
for (int i = split.Length - 1; i >= 0; i--)
{
var mot = split[i];
int nb = -1;
if (int.TryParse(mot, out nb))//c'est un nombre
{
nombre_s = nombre_s.Insert(0, mot);
}
else//c'est la clef
{
clef = clef.Insert(0, mot);
}
}
if (clef.Length == 0 && nombre_s.Length == 0)
{
Console.WriteLine("problème de format ? pas d'info sur cette ligne : {0}", ligne);
continue;
}
Console.WriteLine("Clef : {0}", clef);
Console.WriteLine("Nombre : {0}", int.Parse(nombre_s));//cast pour te montrer que ça passe mais inutile
} |
Partager