0

Sorry if a beginner question, but im trying to read contents from a file in java, and separate 3 strings with a / between them, ex: john/casey/lambert, how would I go along separating these three strings so I can store them into a firstName middleName and lastName variable. Im not sure how to get my scanner or code to recognize the / as a stopping point.

2 Answers2

0

You can take the input in as string s = “John/Casey/lambert” and then you could split it into an array and take the values from there using s.split(“/“, -1)

0
String contents = "john/casey/lambert";
String contentsSplit[] = contents.split("/");

String firstName = contentsSplit[0]; //john
String lastName = contentsSplit[1]; //casey
JonR85
  • 700
  • 4
  • 12