How can I convert a text file into a list of int arrays

后端 未结 5 2009
温柔的废话
温柔的废话 2021-01-16 19:02

I have a text file containing the following content:

0 0 1 0 3 
0 0 1 1 3 
0 0 1 2 3 
0 0 3 0 1 
0 0 0 1 2 1 1 
0 0 1 0 3 
0 0 1 1 3 
0 0 1 2 3 
0 0 3 0 1 
0         


        
5条回答
  •  借酒劲吻你
    2021-01-16 19:55

    Let's say your string is called text, and contains "1 1 1 0 3 2 3" etc. You declare a string array.

    String[] numbers1=text.Split(" ");
    

    Now declare your int array and convert each one to int.

    int[] numbers2=new int[numbers.Length];
    for(int i=0; i

    And you're done.

提交回复
热议问题