2017-04-05 3 views
0

クラスのプロジェクトで作業し、データを配列に読み込んだ後に問題が発生する。CSV入力のインポートと分割

エクセルのスプレッドシートでは、各ブロックの最初の数字だけに注意して列をまっすぐに読む必要があります。私は列を分割するときにスペースがない連続した文字列なので、各桁の数をカウントするのではなく、最初の桁をカウントするしか方法がわかりません。 例:(11、20、296)が分割され、 "1120296" になりつつ

 final int[] benfordLaw = {0, 30, 18, 13, 10, 8, 7, 6, 5, 5}; 
     int[] actualPrecent = new int[10]; 
     int benfordScore = 0; 
     float[] countForNum = new float[10]; 
     float totalCount = 0; 

     //This while loop will read through each line of the file 
     while (scan.hasNextLine()) { 

      // This statement reads in the next line of the file. 
      String line = scan.nextLine(); 

      String[] values = line.split(",(?=(?:(?:[^\"]*+\"){2})*+[^\"]*+$)"); 


      //12-15 is the column #'s 
      for (int i = 12; i < 15; ++i) { 
       for (int j = 0; j < values[i].length(); j++) { 
        char charA = values[i].charAt(j); 
        for (int k = 1; k <= 9; ++k){ 
         char compare = (char)(k + '0'); 
         if (charA == compare) { 
          ++countForNum[k]; 
          ++totalCount; 
         } 
        } 
       } 
      } 
     } 

答えて

0

私は、私は完全にあなたの質問が何であるかを取得していないと思うが、それは

例に役立ちます願っています:(11、 20、296)を使用すると、テキストのみ

読むライン11を取得し、文字列 ソル1を取得したい場合は、「1120296」=>になってきて、分割されて) a)の最初と最後の文字に Bを削除します)Split.Textを作成してトリムします。 c)前記第1の1

ソル2) 使用正規表現を取得し、最初の要素 EX正規表現を取得します。)([0-9] *)、

グッドラック