1
string[][] Chop = null;
string[] Line = null;



private void button1_Click(object sender, EventArgs e)
{
    Line = textBox1.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); // Im succesfull at cutting the input per line and stores it per line in Line variable.

    for(int x = 0;x < Line.Length; x++)
    Chop[][x] = Line[x].Split(' '); 

//I want the Chop to have an array of array of strings.
4

3 回答 3

5

所以你想要行数组,每行一个单词数组:

string[][] lineWords = textBox1.Text
            .Split(new[] { Environment.NewLine }, StringSplitOptions.None)
            .Select(l => l.Split())
            .ToArray();
于 2012-11-02T23:47:08.763 回答
3
var lines = from line in text.Split(new [] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
            select line.Split(new [] {' '}, StringSplitOptions.RemoveEmptyEntries);

lines variable will be of type IEnumerable<string[]>.

If you need Arrays:

var lines = text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(line => line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
                .ToArray();

lines will be string[][]

UPDATE Also I think you can use property Lines of TextBox to get text splittes by lines:

var chop = textBox1.Lines
                   .Select(line => line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
                   .ToArray();
于 2012-11-02T23:42:05.053 回答
1

Although I'm not certain what the exact question is, I do see a problem in the code that is at least related to the title, thus why this is an answer and not a comment.

Firstly, your working with jagged arrays (arrays of arrays), and not multi-dimentional arrays.

... Normally I would give a good description of jagged arrays, but a quick google will probably explain them better than I would, so instead I will end with this: your last line of code should be

Chop[x] = Line[x].Split(' ');
于 2012-11-02T23:41:44.407 回答