简体   繁体   中英

Splitting String from Settings

I'm trying to read out the contents off a Setting inside my Application. Below is the code i'm having troubles with:

private bool checkGrid()
{
    string playlists = Spotify_Extender.Properties.Settings.Default.Playlists;

    MessageBox.Show(playlists);

    string[] split1;

    if (playlists.Contains(";"))
    {
        MessageBox.Show("Multiple Links");
        split1 = playlists.Split(';');
    }
    else
    {
        MessageBox.Show("One Link");
        split1 = new string[1];
        split1[0] = playlists;
    }

    MessageBox.Show("Array Length: " + split1.Length);

    int lines = 0;

    for (int i = 0; i < split1.Length; i++)
    {
        MessageBox.Show("Check #" + i + " - " + split1[i] + " - Length: " + split1[i].Length);
        if (split1[i].Length >= 22)
        {
            MessageBox.Show(i + " - " + split1[1]);
            lines++;
        }
    }

    int rows = this.playlistGrid.Rows.Count;

    MessageBox.Show(lines + "");

    if (rows == lines)
        return true;

    return false;
}

The code should be easy to understand and it should work as far as i am aware, but it doesn't. I entered this in my Setting:

在此处输入图片说明

If i run the program now, my first MessageBox prints out exactly what i entered, the second one prints out "One Link" and the third prints "Array Length: 1". Now we get to the part i'm having troubles with. The next Message is this:

在此处输入图片说明

So the length of the text is 22 as displayed in the MessageBox, but down below this statement isn't true:

if (split1[i].Length >= 22)

I'm really confused by this and it also does this when i check this:

if (split1[i] != "")

Any help is appreciated, because i don't know what to do, since my code should be fine. Thanks for your time!

您应该有split[i]而不是split[1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM