1

これが私が現在行っているサンプルコードです。

string stringWithDelimiters = "Hello%there%people%of%the%world";
string[] vals = new string[30];
vals = stringWithDelimiters.Split('%');

上記のコードから、 の長さはvals6 になります。しかし、30 未満であっても、他の変数の値を空の文字列に設定することによって、配列に 30 すべてを使用するように「強制」する方法はありますか?

4

4 に答える 4

1

This way the array vals will always have 30 elements. First fill the array with 30 empty strings then fill it with the Data that you split. I hope this helped you.

        string stringWithDelimiters = "Hello%there%people%of%the%world";
        string[] vals = new string[30];
        string[] vals1 = new string[30];
        vals1 = stringWithDelimiters.Split('%');
        int valslength = vals1.Length;
        for (int k = 0; k < 30; k++)
        {
            vals[k] = "";
        }
        for (int m = 0; m < valslength; m++)
        {
            vals[m] = vals1[m];
        }
于 2013-06-21T07:50:23.953 に答える