Problem splitting a string

Heya, im trying to read user information from a file.

I know need to split each line into pieces to just obtain their ssn number and password.

But im having a bit of a problem, some lines contain more than just a \t

heres the code

import java.util.regex.*;

import java.io.*;

class Person{

publicstaticvoid main(String[] args)throws IOException, NullPointerException{

BufferedReader myIn =new BufferedReader(new FileReader("persondata.txt"));

String line ="";

String[] words;

for (int a=0; a<7; a++){

line = myIn.readLine();

words = line.split ("\t");

System.out.println (words[0] +" \t " + words[1] +" \t " + words[2] +" \t " + words[3] +" \t " + words[4]);

}

}

}

Heres the text file im trying to read from

namelastnamessnSaleryPassword

BoEk650326-2781105abc123

NisseSvensson801202-122378,5aqw183

HassenKhameli790412-3423120jonas

LisaAndersson760203-343485kla12

JakobNilsson820603-444483sdlksq

EliziReveiro790923-125690lksfj

Some lines to do have more than just one " \t " betwen the words which mess it up.

Im not sure how i can solve this?

Best Regards

Message was edited by:

HolaJawn

[1989 byte] By [HolaJawna] at [2007-11-26 18:50:12]
# 1

\t+ means one or more tabs

I'd use \\t+ in the string literal though, rather than \t+. (two backslashes instead of one)

The string literal "\t" gets turned into an actual tab chacter by the compiler, so the regex will see that. But if you use "\\t", then the compiler uses the first \ in the string literal to escap the second one, so the string that the regex sees is \t, that is, the \ character followed by the letter t, which regex, like the Java compiler, interprets to mean a tab character. It's a minor point, but if you were to examine that regex, it would be easier to read with \t than with an actual tab character.

jverda at 2007-7-9 6:24:14 > top of Java-index,Java Essentials,Java Programming...