我需要以下代码移到下一行,而不是从第一行重新开始
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
}
}
});
正如您在写完空行后所看到的那样,第一行再次重复!
答案 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
中的下一个元素。