How to ignore spaces and blank lines in java

advertisements

and Also because my data contains spaces after or before the comma so I have used a regular expression to brake up the data, So how can I ignore the spaces and how can i break up the data so I can assign them to fields // this is a comment, if the line starts with // // and blank lines as well then ignore them

A, Sanford, Manchester

B , Huddersfield, Oxford

    Scanner scanner = new Scanner(dataFile).useDelimiter(("\\s*,\\s*"));

while(scanner.hasNext() &&(!(line = scanner.nextLine()).startsWith("\\")))
        {

            String lines= scanner.nextLine();

        }


Scanner s = new Scanner(dataFile).useDelimiter("\\s*,\\s*");

This line will use commas as well as whitespace surrounding the comma as the delimiter. So if your data looks like:

A, Sanford, Manchester

B , Huddersfield, Oxford

while (s.hasNext()) {
    System.out.println(s.next());
}

Then the above should output:

A
Sanford
Manchester
B
Huddersfield
Oxford