JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 如何才能抓到字串裡所有MACaddress資料
snowticker0913





發文: 9
積分: 0
於 2014-08-04 14:17 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我將all.txt裡的內容放在all字串裡,想抓出all字串裡的所有MACaddress資料放到Excel的D欄(D2、D3、D4...),我目前是用subString的方法但只能抓到第一筆MACaddress。

字串內容如下:IPAddress={"192.168.20.34","fe80::bd06:5b7f:7fc2:d8c4"}IPConnectionMetric=10MACAddress=EC:A8:6B:2C:BA:8BServiceName=RTL8167DHCPEnabled=TRUEDNSDomain=aromate.comIPConnectionMetric=20MACAddress=B4:B5:2F:82:E9:E4ServiceName=RTL8167

請問各位高手,如何才能把每一筆MACaddress都抓出來放到Excel裡?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
public class code {  
    public static void main(String[] args) throws Exception {
        new code();
    }
 
    public code() throws Exception {
      
 
     FileReader fr = new FileReader("C:\\Users\\kenny.h\\Desktop\\loginfo\\all.txt");
     BufferedReader br = new BufferedReader(fr);
     String str = br.readLine(); //讀第一行
     StringBuffer sb = new StringBuffer();
     
     while ((str = br.readLine())!=null){
       sb.append(str);
       }
     
     String all = sb.toString();
     
 
     String MACAddress = sb.substring(all.indexOf("MAC"), all.indexOf("Service"));
 
     WritableWorkbook workbook = Workbook.createWorkbook(new File("C:/Users/kenny.h/Desktop/123.xls"));
     WritableSheet sheet = workbook.createSheet("Sheet", 0);
     
 
         String A1 = "UserName";
         String B1 = "DNSHostName";
         String C1 = "IPAddress";
         String D1 = "MACAddress";
         String E1 = "Manufacturer";
         String F1 = "Model";
         String G1 = "廠區";
         String H1 = "部門";
         sheet.addCell(new Label(0, 0, A1));
         sheet.addCell(new Label(1, 0, B1));
         sheet.addCell(new Label(2, 0, C1));
         sheet.addCell(new Label(3, 0, D1));
         sheet.addCell(new Label(4, 0, E1));
         sheet.addCell(new Label(5, 0, F1));
         sheet.addCell(new Label(6, 0, G1));
         sheet.addCell(new Label(7, 0, H1));
         
     
        workbook.write();
        workbook.close();
        System.out.println("down");
    }
}


snowticker0913 edited on 2014-08-04 14:19
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
674 如何才能抓到字串裡所有MACaddress資料 snowticker0913 1943 2014-08-04 14:17
563 Re:如何才能抓到字串裡所有MACaddress資料 roytsang 698 2014-08-04 15:23
545 Re:如何才能抓到字串裡所有MACaddress資料 snowticker0913 35 2014-08-04 16:09
542 Re:如何才能抓到字串裡所有MACaddress資料 roytsang 24 2014-08-04 16:13
550 Re:如何才能抓到字串裡所有MACaddress資料 snowticker0913 493 2014-08-04 17:30
515 Re:如何才能抓到字串裡所有MACaddress資料 snowticker0913 152 2014-08-04 17:45
525 Re:如何才能抓到字串裡所有MACaddress資料 roytsang 17 2014-08-04 17:47
481 Re:如何才能抓到字串裡所有MACaddress資料 snowticker0913 139 2014-08-05 09:02
481 Re:如何才能抓到字串裡所有MACaddress資料 roytsang 38 2014-08-05 09:53
466 Re:如何才能抓到字串裡所有MACaddress資料 snowticker0913 2388 2014-08-05 10:21
459 Re:如何才能抓到字串裡所有MACaddress資料 snowticker0913 76 2014-08-05 11:31
433 Re:如何才能抓到字串裡所有MACaddress資料 roytsang 36 2014-08-05 13:59
437 Re:如何才能抓到字串裡所有MACaddress資料 snowticker0913 71 2014-08-05 14:00
449 Re:如何才能抓到字串裡所有MACaddress資料 roytsang 68 2014-08-05 14:09
422 Re:如何才能抓到字串裡所有MACaddress資料 T55555 604 2014-08-06 04:02
405 Re:如何才能抓到字串裡所有MACaddress資料 roytsang 12 2014-08-06 10:05
400 Re:如何才能抓到字串裡所有MACaddress資料 snowticker0913 4 2014-08-06 17:38
» JWorld@TW »  Java 新手區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8