I want to split the String String line = "20E WED 01PM 0E";
so that I have variables for each "part," where the parts would look something like:
int fDegree = 20;
String fDegreeEW = "E";
String day = "WED";
int time = 01; \\ '1' is fine too
String amPm = "PM";
int sDegree = 0;
String sDegreeEW = "E";
I was thinking of first splitting the String line
at spaces and then doing regex
on each part to get the data, but I couldn't get that to work. What would be the nicest way to split a String like this into a bunch of different variables? Note: This is not the only String I want to check. The first "20" could also be "1" or "165", for example, so the words and numbers do not necessarily have a set length. But the pattern of number, word, space, word, space, number, word, space, number, word will always be true.
Edit: I tried:
String line = "20E WED 01PM 0E";
String[] splitArray = line.split(" ");
Scanner scanner = new Scanner(splitArray[0]);
int fDegree = scanner.nextInt();
but that threw an InputMismatchException
. Can I use scanner here or no?