particularly from a txt file. for example if the file reads "name ###-####-#### address" all in one single line. how do i put all three items in three separate variables and print them?

Recommended Answers

All 2 Replies

regular expressions could help you to check and then parse your string :

//a name followed by 4 sequences of 4 numbers, and an adress.
Pattern p = Pattern.compile("^(.+) ([0-9]{4})-([0-9]{4})-([0-9]{4})-([0-9]{4}) (.+)$");
Matcher m = p.matcher(inputString);
   String name =;
   int a0 = Integer.parseInt(;
   int a1 = Integer.parseInt(;
   int a2 = Integer.parseInt(;
   int a3 = Integer.parseInt(;
   String adress =;
else throw new IllegalArgumentException("invalid syntax");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.