index no.student room

41 18 M.OPERASI
41 27 M.OPERASI
41 PODIUM
41 24 PODIUM
41 25 PODIUM
41 19 B 206/207

this is a part of data in a text file that i will read and place it in array and save it in another text file..


but i got problem to read empty data at the middle..

i got around 5000 data and there are a lot of empty data for no.student column. it hard for me to place 0 at every empty space before i can read properly using filereader.

a question is, is there any way i can read that empty data and assign 0 to its array variable?

sorry, my english is poor

Recommended Answers

All 9 Replies

Not sure exactly how your reader program is set up, but you could have it read char by char and when it encounters a space (' ') you could instead set the char equal to 0 ('0'). So,

char readChar; //The character read by the reader

if(readChar==' ') readChar='0';

//do whatever you want to do with it then

problem to read empty data

Can you define what "empty data" is?
Is the data file in text? Is there a newline character at the end of every line?
Would an empty line be one with no data between two newline characters?

Your posted example does NOT show where the "empty data" is?
Do you mean there is a missing "column"? For example this line: 41 PODIUM is missing a numberic value in the 2nd column

What classes are you using to read the data?

the third data for 2nd column is empty.. -->> 41 (null) PODIUM
and i wonder if there any way to read it as null and place it as 0 in array..
if this only a data that missing then its ok for me to edit but there a lot of empty for 2nd column in 5000 data.. so i hope there are solution for this..

oh thanks pi lord12, ill try to write it^^

What format is the input file in? How is a null value represented in the file?

Your first example showed that the data for the second column was missing.
If there is a null value there then you could use that.

You understand that a null value is a value. A missing value is not a value. There is nothing there.

that not null but empty data.. 41 podium..
if null then i can solve it.. and yeah it missing value..
i dont know why they(i mean my faculty) dont want to place 0 instead by leaving it empty.. thanks for response NormR1

lol why i put 4 space between 41 and podium still got so close??

Can your code recognize that column 2 is missing?
If so, you could write code to insert a default value.
If you can't recognize that a specific column is missing, I don't know how to solve the problem.

What are the constraints on the data? Index is always an integer, right? Is your second column always an integer? Does your third column always begin with an alpha character? If so, you should be okay. Read the index. Read the next item. If it's an integer, it's a "no. student". If it's not an integer, fill in some "no data here" signal*, and read the next item. That should be your room.

Each line is an int followed by one optional int followed by one (possibly optional) String. That's not hard to parse.

*Is zero sometimes a valid value for "no. student"? If so, think about using -1 or some other distinct value to tell you that this was "no data", and not "a class with zero students".

ohh i see.. it work..
it much easier than i think..
oh thanks jon.kiparsky for answering my problem..
and thanks normR1 for try answering..

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.