×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Hi i need to separate 1 text fil

Hi i need to separate 1 text fil

Hi i need to separate 1 text fil

(OP)
Hi

i need to separate 1 text file into 100 records in each file, so my logic create those text file, but the data is not complete in each text file, 5 records are missing.

In this code, first i load all records into a listbox, then try to separate them in 100s

private void WriteToFile()
{
int RowCount = listBox1.Items.Count;
string FileName = "C:\\Users\\bbdnet0986\\Documents\\MyExpotedQADATA";
StreamWriter sw = new StreamWriter(FileName + ".txt");
int inc = 0;
int counter = 0;
//StreamWriter sw = new StreamWriter(FileName+inc + ".txt");
for (int i = 0; i < listBox1.Items.Count; i++)
{
sw.WriteLine(listBox1.Items[i].ToString());
string me = listBox1.Items[i].ToString();

if (RowCount > 100)
{

listBox2.Items.Add(listBox1.Items[counter].ToString());
counter++;
if (counter == 100)
{

inc++;
sw = new StreamWriter(FileName + inc + ".txt");

//counter = counter - 100;
RowCount = RowCount - counter;
counter = 0;
//FileName = FileName + inc + ".txt";
}
}

else
{
sw.WriteLine(listBox1.Items[i].ToString());
}

}
sw.Close();
}

RE: Hi i need to separate 1 text fil

homework? okay, try to code this pseudo:

CODE

function main()

  let sourceStream = open source file
  let filecounter = 1

  while sourceStream NOT eof
    call copyLines(sourceStream, filecounter)
    increment filecounter
  loop

end function


function copyLines(sourceStream, filecounter)
  let linecounter = 1
  let file = "file" + filecounter
  open newbuffer

  while sourceStream NOT eof and linecounter not 100
    let line = read sourceStream
    write to newbuffer
    increment linecounter
  loop

end function 
It's not a perfect pseudo but this should give you an idea.
wink

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close