0

Есть текстовый файл с данными формата string, string. Записанный в текстовый файл вида: [2019-12-23 21:00:00Z , 1] Запятая разделитель. Перевод данных из файла в коллекцию идет по алгоритму:

var assembly = 
IntrospectionExtensions.GetTypeInfo(typeof(MainPage)).Assembly;
        Stream stream = 
assembly.GetManifestResourceStream("App255555.myfile.txt");
        string text = "";
        using (var reader = new System.IO.StreamReader(stream))
        {

            string line = null;

            // while it reads a key
            while ((line = reader.ReadLine()) != null)
            {
                // add the key and whatever it 
                // can read next as the value
                Dict2020.year2020Dict.Add(line, reader.ReadLine());
            }
            //text = reader.ReadToEnd();
        }

Файл читается. Но при проверке значений в коллекции, пишет, что там нет значений.

        ListView lv = new ListView();

        lv.ItemsSource = Dict2020.year2020Dict.Keys;

        string hhh = "2019-12-22 21:00:00Z";

        text = Dict2020.year2020Dict[hhh];


        Label label = new Label
        {
            VerticalTextAlignment = TextAlignment.Center,
            HorizontalTextAlignment = TextAlignment.Center,
            Text = text,
            FontSize = Device.GetNamedSize(NamedSize.Large, 
            typeof(Label))
        };

        Content = label;

Буду благодарен любой помощи.

2
  • 1
    не знаете как строку разбить по запятой? рано в xamarin лезть ....
    – Question1
    10 янв 2020 в 11:11
  • Спасибо за ответ.
    – Pvl Pa
    10 янв 2020 в 11:37

1 ответ 1

0

Решение:

            while ((line = reader.ReadLine()) != null)
            {
                string[] dictonaryKeyValue = new string[2];
                dictonaryKeyValue = line.Split(',');

 Dict2020.year2020Dict.Add(dictonaryKeyValue[0],dictonaryKeyValue[1]);

            }

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.