Liutauras Vilda wrote:Try to add simple print statements by printing out the length of array after you split the line/record, so you'd see how many elements in it before you access element at particular index and you'll see where the things fall apart. Don't be scared to use print statements, these can tell you helpful things.
You can add also counter, so you'd know at which line the amount of elements differs.
That first bit is not a regular expression, it is a string literal. Forget about that at the moment (i'm not sure you'll need that at all). Get first things done.saeid jamali wrote:"[a-zA-Z]".equals(fields[0])
saeid jamali wrote:I'm not sure if I'm using the right regex cause it's not working....
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
saeid jamali wrote:I'm not sure if I'm using the right regex cause it's not working....
I suspect you're going the wrong way about this. Basically, what you want to know is when a line DOES contain values, not when it doesn't.
So what you need is a regex that checks whether a "field" IS a valid 'value' or not - ie, a number or "---".
And a valid record is a line that contains at least 7 valid 'values'.
One possibility might be something like this:I've listed it out in detail to explain how it works, but you can just make it a single string if you want.
Have a look at what I posted earlier to see if it makes sense now.
HIH
Winston
saeid jamali wrote:I know it's a bad idea but I don't want my code to get so complex...
I made if statement for very parse and now it's working perfectly.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Hardwork beats talent when talent fails to work hard
Love the life you live.