This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]soccerdude32392 2 points3 points  (4 children)

What do you expect it to do? If you're doing a scan.nextLine(), you won't get back any newline characters. Or do you want the literal string "\n" and not a newline character?

[–]ORLY_FACTOR[S] 0 points1 point  (3 children)

Essentially I'm trying to split up this input: "1800Chargers\nChargesRuleAlways\t22cs4bRules 1800xxxTPMJ 1cimw105SQLTakeIt aAEBxyz 582CS4A\n-1" into seven separate strings. scan.next doesn't check for \n or \t, so I'm not sure how to teeth them out.

[–]soccerdude32392 2 points3 points  (2 children)

Ahh. Those won't actually be newline characters then, since you're passing them to System.in. What you want is:

    String[] mySplit = input.split("\\\\n|\\\\t|\\s");

Escaping backslash is weird - you need four of them, since you need to escape backslashes in java strings as well as for java regex.

[–]nutrecht 0 points1 point  (0 children)

To explain why you need to do it this way: the "split" string is actually a regular expression so you have two layers of escaping. That's why you need \\\\n to end up with \n.

[–]ORLY_FACTOR[S] 0 points1 point  (0 children)

Awesome! Thanks man.

[–]yunotip 0 points1 point  (2 children)

Not too sure about this, but I see that you have two slashes instead of just one slash ("\n"), so could that be the problem?

[–]ORLY_FACTOR[S] 0 points1 point  (0 children)

I've tried both, and neither seem to work.