Diskuze: Parser pole a nasledny string
V předchozím kvízu, Test znalostí C# .NET online, jsme si ověřili nabyté zkušenosti z kurzu.
Zobrazeno 6 zpráv z 6.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
V předchozím kvízu, Test znalostí C# .NET online, jsme si ověřili nabyté zkušenosti z kurzu.


Moc tomu zadání nerozumím. To chceš jako něco takového?
if(i == 10) ?
else if(i == 11) zpracuj frontu
else přidej i do fronty
btw, originál zadání by byl asi lepší.
Ahoj,
prikladam mozny parser, ktory predpoklada, ze je v poli test max 10 stringov,
ked tak si uprav na viac při deklaracii:
string[] parsed = new string[10];
int counted = 0;
if (test[0] == 11)
{
    string single = "";
    int position = 1;
    while (position < test.Length)
    {
        if (test[position] == 10)
        {
            parsed[counted] = single;
            counted++;
            single = "";
        }
        else
        {
            single = single + (char)test[position];
        }
        position++;
    }
}
foreach (string s in parsed)
    Console.WriteLine(s);
Console.WriteLine("pocet retezcu = " + counted.ToString());
Console.ReadKey();
					Když už jsem to napsal...
static void Main(string[] args)
        {
            byte[] test = new byte[] { 65, 66, 67, 10, 65, 66, 67, 10, 65, 66, 67, 10, 10, 10, 10, 10, 10 };
            if (test[0] == 11) Console.WriteLine("Identifikátor je 11!");
            else
            {
                string[] lines = ParseTextFromBytes(test);
                foreach (string line in lines) Console.WriteLine(line);
            }
            Console.ReadKey();
        }
        static string[] ParseTextFromBytes(byte[] bytes)
        {
            string str = System.Text.Encoding.GetEncoding(1250).GetString(bytes);
            return str.Split(new char[]{'\n'}, StringSplitOptions.RemoveEmptyEntries);
        }
					pardon, já jsem to udělal obráceně. Oprava:
    byte[] test = new byte[] {11, 65, 66, 67, 10, 65, 66, 67, 10, 65, 66, 67, 10, 10, 10, 10, 10, 10 };
    if (test[0] != 11) Console.WriteLine("Identifikátor není 11!");
    else
    {
        string[] lines = ParseTextFromBytes(test);
        foreach (string line in lines) Console.WriteLine(line);
    }
    Console.ReadKey();
}
static string[] ParseTextFromBytes(byte[] bytes)
{
    string str = System.Text.Encoding.GetEncoding(1250).GetString(bytes);
    return str.Split(new char[]{'\n', '\v'}, StringSplitOptions.RemoveEmptyEntries);
}
					
						Zobrazeno 6 zpráv z 6.