移动到数组的下一个元素

时间:2016-06-08 14:45:42

标签: java for-loop

我需要以下代码移到下一行,而不是从第一行重新开始

public void actionPerformed(ActionEvent e) {                
    String getTextArea;
    getTextArea = textArea.getText();
    String[] arr = getTextArea.split("\\n");
    String type = null;
    String serial = null;
    try {
        for(String s : arr) {                       
        if(s.isEmpty()) {
        textArea_1.append("Empty line" + '\n');
        s = getTextArea;
        }
    type = s.substring(0, 4);
    serial = s.substring(5, 12);
    URL url = new URL("blablabla" + type + serial);
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                    String result;
                    Scanner sc; 
                    sc = new Scanner(in);  
                    while(sc.hasNext()) {
                        result = sc.next();
                if (result.contains("Type:")) {
                            result = sc.nextLine();
                            result = sc.nextLine();
                            result = result.substring(26,30);
                            textArea_1.append(result + '\t');
                        }
                            result = sc.nextLine();
                            result = sc.nextLine();
                            result = result.substring(26, 29);
                            textArea_1.append(result + '\t');                               
                           }
                    }                       
                }   
            } catch (Exception e2) {
                // TODO: handle exception
            }
        } 
    });

这是显示结果的图片 enter image description here

正如您在写完空行后所看到的那样,第一行再次重复!

1 个答案:

答案 0 :(得分:0)

我认为if块中的s = getTextArea;代替continue;,您应该arr前进到 snRow = Columns(1).Find(What:="SN= ", _ After:=ActiveCell, _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False, _ SearchFormat:=False).Row Range("A" & (snRow + 1)).Select 'select serial number cell in Temp WorkBook Selection.Copy wrksht.Activate Range("B1").Select wrksht.Paste wbImport.Activate 中的下一个元素。