Because nextLine()
doesn't care about delimiters. The delimiters only affect Scanner
when you tell it to return tokens. nextLine()
just returns whatever is left on the current line without caring about tokens.
A delimiter is not the way to go here; the purpose of delimiters is to tell the Scanner
what can come between tokens, but you're trying to use it for a purpose it wasn't intended for. Instead:
String n = s.nextLine().replaceFirst("^a=","");
This inputs a line, then strips off a=
if it appears at the beginning of the string (i.e. it replaces it with the empty string ""
). replaceFirst
takes a regular expression, and ^
means that it only matches if the a=
is at the beginning of the string. This won't check to make sure the user actually entered a=
; if you want to check this, your code will need to be a bit more complex, but the key thing here is that you want to use s.nextLine()
to return a String
, and then do whatever checking and manipulation you need on that String
.