I have a text file in the following format:
0 (1, 10), (0, 5), (3, 40)
1 (2, 15), (1, 23), (2, 18), (4, 5), (3, 50)
2 (3, 100)
The first number in every line is used for a specific purpose. Similarly, each of the integers in parenthesis is used for another specific purpose. Therefore, I am trying to extract each of these integers separately. This is what I have tried:
BufferedReader br = new BufferedReader(new FileReader("test.txt"));
String line = br.readLine();
while (line != null) {
String[] separate = line.split(", ");
for (int i = 0; i < patterns.length; i++) {
String result = separate[i].replace("(", "").replace(")", "");
}
}
While this does extract each integer, there is no distinction between the integers in brackets and the first one in the line. Also, this solution does not separate each line in the file.
Could someone please assist me with a better solution to this?