我在java中編寫了一個小型文本文件解析器,我需要在Visual Basic中重做它,所以簡單的exe可以從PC移動到PC。VB在文本文件中讀取時跳過行
我無法讓VB 2010快速省略帶關鍵字的行。
這裏是工作
public static void main(String[] args) {
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(new File("/Users/leighlarue/Desktop/9-18-13.cap")));
StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line = bufferedReader.readLine()) != null) {
Pattern pattern = Pattern.compile("ALL|MESSAGE|Time|PAPER_MAIN|paper_proc|IOMASTER|Options:|ERROR|Message|BAD GAUGE|Errors|GSP");
if (pattern.matcher(line).find()) {
continue;
}
stringBuffer.append(line);
stringBuffer.append("\n");
}
BufferedWriter bwr = new BufferedWriter(new FileWriter(new File("/Users/leighlarue/Desktop/Stage_One.txt")));
bwr.write(stringBuffer.toString());
bwr.flush();
bwr.close();
//System.out.println(stringBuffer);
} catch (IOException e) {
}
}
}
有人可以幫我這個轉換爲Visual Basic中,請在Java?
我想做...
Dim strFile As String = TextBox1.Text
' open file into stream reader
Dim sr As New StreamReader(strFile)
Dim line As String
' get the first line
While sr.Peek <> -1
line = sr.ReadLine()
If line.Contains("MESSAGE") Then
Continue While
End If
RichTextBox1.Text += line + CtrlChars.CrLf
' lineRead = sr.ReadLine()
End While
End Sub
使用正則表達式,它將允許您定義更符合您在Java中做什麼的模式。 http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex%28v=vs.110%29.aspx – 2014-12-03 15:53:47