2009-11-19 74 views
2

這是Akshatha。我被困在解析下面的數據。我想單獨提取每個單詞。我可以有一個示例代碼,以便我可以繼續如何解析此輸出並分隔每個字段/單詞

RTRV-HDR RH01 


    SIMULATOR 09-11-18 16 13 19 


M RH01 COMPLD 


RTRV-EQPT ALL RE01 


    SIMULATOR 09-11-18 16 13 20 


M RE01 COMPLD 


    SLOT-1-1-1 CMP IS-NR 


    SLOT-1-1-2 CMP IS-NR 


    SLOT-1-1-3 OLC IS-NR 


    SLOT-1-1-4 OLC IS-NR 


    SLOT-1-1-5 OLC IS-NR 


    SLOT-1-1-6 OLC IS-NR 


    SLOT-1-1-7 OLC IS-NR 


    SLOT-1-1-8 OLC IS-NR 


    SLOT-1-1-9 IOC IS-NR 


    SLOT-1-1-10 IOC IS-NR 


    SLOT-1-2-1 NMC IS-NR 


    SLOT-1-2-2 NMC IS-NR 


    SLOT-1-2-3 OLC IS-NR 


    SLOT-1-2-4 OLC IS-NR 


    SLOT-1-2-5 OLC IS-NR 


    SLOT-1-2-6 OLC IS-NR 


    SLOT-1-2-7 OLC IS-NR 


    SLOT-1-2-8 OLC IS-NR 


RTRV-ALM-EQPT ALL RA01 


    SIMULATOR 09-11-18 16 13 21 


M RA01 COMPLD 


    SLOT-1-1-1 CMP MN T-FANCURRENT-1-HIGH NSA 01-10-09 00-00-00 \Fan-T\ 


    SLOT-1-1-1 CMP MJ T-BATTERYPWR-2-LOW NSA 01-10-09 00-00-00 \Battery-T\ 


    SLOT-1-1-2 CMP CR PROC_FAIL SA 09-11-18 16-12-59 \Processor Failure\ 


    SLOT-1-1-3 OLC MN T-LASERCURR-1-HIGH SA 01-10-07 13-21-03 \Laser-T\ 


    SLOT-1-1-3 OLC MJ T-LASERCURR-2-LOW NSA 01-10-02 21-32-11 \ Laser-T\ 


    SLOT-1-1-4 OLC MN T-LASERCURR-1-HIGH SA 01-10-05 02-14-03 \Laser-T\ 


    SLOT-1-1-4 OLC MJ T-LASERCURR-2-LOW NSA 01-10-04 01-03-02 \Laser-T\ 


RTRV-ALM-EQPT ALL RA02 MJ 

    SIMULATOR 09-11-18 16 13 21 


M RA02 COMPLD 


    SLOT-1-1-1 CMP MJ T-BATTERYPWR-2-LOW NSA 01-10-09 00-00-00 \Battery-T\ 


    SLOT-1-1-3 OLC MJ T-LASERCURR-2-LOW NSA 01-10-02 21-32-11 \ Laser-T\ 


    SLOT-1-1-4 OLC MJ T-LASERCURR-2-LOW NSA 01-10-04 01-03-02 \Laser-T\ 


RTRV-ALM-EQPT ALL RA03 MN 


    SIMULATOR 09-11-18 16 13 22 


M RA03 COMPLD 


    SLOT-1-1-1 CMP MN T-FANCURRENT-1-HIGH NSA 01-10-09 00-00-00 \Fan-T\ 


    SLOT-1-1-3 OLC MN T-LASERCURR-1-HIGH SA 01-10-07 13-21-03 \Laser-T\ 


    SLOT-1-1-4 OLC MN T-LASERCURR-1-HIGH SA 01-10-05 02-14-03 \Laser-T\ 


RTRV-ALM-EQPT ALL RA04 MN T-LASERCURR-1-HIGH 


    SIMULATOR 09-11-18 16 13 22 


M RA04 COMPLD 


    SLOT-1-1-3 OLC MN T-LASERCURR-1-HIGH SA 01-10-07 13-21-03 \Laser-T\ 


    SLOT-1-1-4 OLC MN T-LASERCURR-1-HIGH SA 01-10-05 02-14-03 \Laser-T\ 


RTRV-PM-EQPT ALL RP01 


    SIMULATOR 09-11-18 16 13 23 


M RP01 COMPLD 


    SLOT-1-1-1 CMP FANCURRENT-1 180.080  


    SLOT-1-1-1 CMP FANCURRENT-2 204.660  


    SLOT-1-1-1 CMP FANCURRENT-3 230.500  


    SLOT-1-1-1 CMP FANCURRENT-4 187.580  


    SLOT-1-1-1 CMP BATTERYPWR-1 53.650  


    SLOT-1-1-1 CMP BATTERYPWR-2 53.650  


    SLOT-1-1-2 CMP FANCURRENT-1 180.080  


    SLOT-1-1-2 CMP FANCURRENT-2 204.660  


    SLOT-1-1-2 CMP FANCURRENT-3 230.500  


    SLOT-1-1-2 CMP FANCURRENT-4 187.580  


    SLOT-1-1-2 CMP BATTERYPWR-1 53.650  


    SLOT-1-1-2 CMP BATTERYPWR-2 53.650  


    SLOT-1-1-3 OLC LASERPWR-1 200.00  


    SLOT-1-1-3 OLC LASERPWR-2 200.00  


    SLOT-1-1-4 OLC LASERPWR-1 200.00  


    SLOT-1-1-4 OLC LASERPWR-2 200.00  


    SLOT-1-1-5 OLC LASERPWR-1 200.00  


    SLOT-1-1-5 OLC LASERPWR-2 200.00  


    SLOT-1-1-6 OLC LASERPWR-1 200.00  


    SLOT-1-1-6 OLC LASERPWR-2 200.00  


    SLOT-1-1-7 OLC LASERPWR-1 200.00  


    SLOT-1-1-7 OLC LASERPWR-2 200.00  


    SLOT-1-1-8 OLC LASERPWR-1 200.00  


    SLOT-1-1-8 OLC LASERPWR-2 200.00  


    SLOT-1-2-3 OLC LASERPWR-1 200.00  


    SLOT-1-2-3 OLC LASERPWR-2 200.00  


    SLOT-1-2-4 OLC LASERPWR-1 200.00  


    SLOT-1-2-4 OLC LASERPWR-2 200.00  


    SLOT-1-2-5 OLC LASERPWR-1 200.00  


    SLOT-1-2-5 OLC LASERPWR-2 200.00  


    SLOT-1-2-6 OLC LASERPWR-1 200.00  


    SLOT-1-2-6 OLC LASERPWR-2 200.00  


    SLOT-1-2-7 OLC LASERPWR-1 200.00  


    SLOT-1-2-7 OLC LASERPWR-2 200.00  


    SLOT-1-2-8 OLC LASERPWR-1 200.00  


    SLOT-1-2-8 OLC LASERPWR-2 200.00  


    INIT-SYS SLOT-1-1-2 IS01 1 


    SIMULATOR 09-11-18 16 13 23 


M IS01 COMPLD 

感謝您的寶貴回覆。

+0

因此,您設法避免了以前的所有垃圾。 ;) – 2009-11-19 06:28:36

回答

2

我會嘗試String.split()。像這樣的東西...
String [] words;
words = line.split("\s+");

上面將字符串分割成空白。

1

使用BufferedReader來讀取您的文件(或輸入流)thusly

然後使用StringTokenizer分割每行到令牌thisly

我不是在這裏提供一個隨時可以使用的代碼,因爲我想你會學會按照上面的例子組合成一個工作代碼自己更好。

1

如何使用Stringtokenizer獲取每個單詞?

import java.util.*; 
public class ReverseWords { 
    public static void main(String args[]) { 
     String s = "Go to the main menu. Quick!"; 
     StringTokenizer tokens = new StringTokenizer(s); 
     StringBuffer ab; 

     while (tokens.hasMoreTokens()){ 
      ab = new StringBuffer (tokens.nextToken()); 
      // do your processing 
     } 
     System.out.println(); 
    } 
} 
+0

對循環內部的StringBuffer的使用感到好奇......它似乎在表面上是無關緊要的。也許是從原來的代碼持有? – PSpeed 2009-11-19 07:52:20

+0

@PSpeed確實來自原始代碼,其處理涉及大量字符串聚合。 – VonC 2009-11-19 09:56:32

相關問題