separates string to put it in a datagrid

0

hello could you help me to separate that string that I have from a list to separate it and put where it says name and password in columns of a datagrid I have already tried with slipt but I have not managed it

foreach (string item in mk.Read())
            {
                listBox3.Items.Add(item);
               x+=item;

            }
            string[] words = Regex.Split(x, "=");

            foreach (var item in words)
            {                   
                listBox1.Items.Add(item);

                //if (item == "name")
                //    listBox2.Items.Add(item.Count());


            }

thank you very much.

    
asked by carlos1016 06.11.2018 в 03:41
source

1 answer

1

Maybe you can do something like this:

string[] words = x.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
string n = null;
string p = null;
for (int i = 0; i < words.Length - 1; i++)
{                   
    switch (words[i]){
        case "name":
            n = words[i + 1];
            break;
        case "password":
            p = words[i + 1];
            break;
    }
}
if (!string.IsNullOrEmpty(n) && !string.IsNullOrEmpty(p)) {
    listBox2.Items.Add(p);
    listBox1.Items.Add(n);
}

In the example when I find a name I add it to the listBox1 and when I find a key I add it to the listBox2, but you can modify it so that it can be added to where you need it.

I hope it serves you.

Good luck!

    
answered by 06.11.2018 / 03:52
source