There is a file.txt that contains:
Country,Province/State,City
So I wanted to use "," as my delimiter. However, some lines of this file have:
Country,"Name1 and Name2, Province of",City
So using a comma as a delimiter would not work as the above example as a comma in the Province name.
This is my code:
String path = workingDir + "/src/main_pkg/File.txt";
    File file = new File(path);
    Scanner sc = null;
    try {
        sc = new Scanner(file);
    } catch (FileNotFoundException e) {
        System.out.println(new File("."));
        e.printStackTrace();
    }
    ObservableList<String> listOfProvinces = FXCollections.observableArrayList();
    String country;
    String state= "";
    String lastState = "";
    sc.useDelimiter(",");
    while (sc.hasNext()) {
        country = sc.next();
        province = sc.next();
        if (country.matches(countryComboBox.getValue())) {
            if (!province.matches(lastState)) {
                listOfStates.add(state);
                lastState = state;
            }
        }
        sc.nextLine();
    }
    sc.close();
To clarify, I cannot modify the txt file.
 
    