Hi i have been asked to create a sample app which pulls data from a txt file. Then outputs it in another txt document depending on certain arguments.

Write a console application called 'program.exe' that takes four arguments:
1. Input File
2. Output File
3. Log File
4. Product Codes delimited by comma

example: extract.exe c:\process.txt c:\output.txt c:\log.txt "ABC,123"

I know this is a bit cheeky, but i am unsure where to start as i am just starting out in Windows C# Apps. So any help would be much appreciated. Ideally it would be good if anyone has any links to sites so i can read up on how to create this so i can learn too.

Much appreciated.

OK. Here is a method of getting started.
You will still need to Read a Line from the input file in a looping manner and Write a Line to the output file.
But with this example, you should be able to see what to read in the help file or on MSDN to figure out how to use those classes.

using System;
using System.IO;

namespace DW_403813
{
   class Program
   {
      static void Main(string[] args)
      {
         StreamReader fileIn = new StreamReader(args[0]);
         StreamWriter fileOut = new StreamWriter(args[1]);
         StreamWriter fileLogOut = new StreamWriter(args[2]);
         string[] arr_strInputData = args[3].Split(" ,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

         fileLogOut.Close();
         fileOut.Close();
         fileIn.Close();
      }
   }
}

Edited 4 Years Ago by thines01: TMI

Think i need more of a hand... i know i need to use the StreamReader and StreamWriter.
Below is what i have been asked to do...

I am pretty new to console apps, so its kinda got me lost lol :) so any additional help would be much appreciated. Many Thanks in advance.

Write a console application called 'program.exe' that takes four arguments:
1. Input File
2. Output File
3. Log File
4. Product Codes delimited by comma

example:
extract.exe c:\process.txt c:\output.txt c:\log.txt "acb,123"


The program should produce a output file that is the a copy of the input file however NOT contain any records that have a product code
matching the product codes provided as the 4th argument.

A record is defined by the tag:
header-PolicyDocumentation-[POLICY NUMBER]

the end of the record is defined by the tag:
end-PolicyDocumentation-[POLICY NUMBER]

example:

header-PolicyDocumentation-12 --------- START OF RECORD
UnderwriterName=IPA
UnderwriterCode=001
TotalvalueofDiscounts=£0.00
ProductCode=abc
end-PolicyDocumentation-12 ---------- END OF RECORD
header-PolicyDocumentation-45 --------- START OF RECORD
UnderwriterName=IPA
UnderwriterCode=004
TotalvalueofDiscounts=£0.00
ProductCode=LA
end-PolicyDocumentation-45 ---------- END OF RECORD


if we were to run the program against an input file that contains the data above and specified the product code "abc" then the
output file would be as follows:

header-PolicyDocumentation-45
UnderwriterName=IPA
UnderwriterCode=004
TotalvalueofDiscounts=£0.00
ProductCode=LA
end-PolicyDocumentation-45

Edited 4 Years Ago by influenceuk: n/a

Are you familiar with classes?
What I would write next will not be any simpler.

Edited 4 Years Ago by thines01: clarity

Are you familiar with classes?
What I would write next will not be any simpler.

A little, but seeing sample code helps a lot, and i am able to learn from it :) Most examples i get i step through and see how they are working so i get a better understanding of things :)

Regards

OK. How would you choose to fill a class like this?:

public class CPolicyDoc
   {
      public string strUnderwriterName { get; set; }
      public string strUnderwriterCode { get; set; }
      public double dblTotalvalueofDiscounts { get; set; }
      public string strProductCode { get; set; }

      public CPolicyDoc()
      {
         strUnderwriterName = "";
         strUnderwriterCode = "";
         dblTotalvalueofDiscounts = 0.0;
         strProductCode = "";
      }

      public CPolicyDoc(CPolicyDoc copy)
      {
         strUnderwriterName = copy.strUnderwriterName;
         strUnderwriterCode = copy.strUnderwriterCode;
         dblTotalvalueofDiscounts = copy.dblTotalvalueofDiscounts;
         strProductCode = copy.strProductCode;
      }

      public override string ToString()
      {
         return
            strUnderwriterName + '-' +
            strUnderwriterCode + '-' +
            dblTotalvalueofDiscounts.ToString() + '-' +
            strProductCode;
      }

      public override int GetHashCode()
      {
         return this.ToString().GetHashCode();
      }

      public override bool Equals(object obj)
      {
         return this.ToString().Equals(((CPolicyDoc)obj).ToString());
      }
   }

Edited 4 Years Ago by thines01: n/a

tbh not too sure. however i can see that you are pulling in the details that are needed, depending on the requested details.

Then copying the items.

I would guess that how its working?

thines01 off topic a little, how long have you been coding for, and can you recommend any good books to learn from?

btw sorry for my ignorance, i am still learning. I have been doing web (asp.net) yet still dont know all that lol :)

I like WROX books, but that depends on what you're trying to learn.
You can learn something from almost any book you find.
You can also learn a lot by looking at video content like on DNRTV.
There is so much free content floating around the web that you can learn a lot without spending any additional money.

So with your data, you will simply ignore the markers that denote the start and end of the record and simply read, parse and store the pieces of content you need.

Are you faniliar with iterating through files?

Also, if you have a product code, why do you need the 12 and the 45 on the header/footers?

Edited 4 Years Ago by thines01: confused

no :(

but i was reading something on MSDN earlier about it. Thanks for your help btw

Well, if I provide too much help, you might not be able to explain it.
Have you written the part to read the input file line-by-line?

Well, if I provide too much help, you might not be able to explain it.
Have you written the part to read the input file line-by-line?

you mean the large bit of code and the smaller, or just the large bit?

When you loop through the file, you can either count lines to determine which element of the record to add the to the class or you can read the contents to determine which elemen you're going to add to the class.

Every time you encounter "header-" at the start of a line, create a new CPolicyDoc object.

Every time you encounter "end-", add the CPolicyDoc object to your master collection.

For this, I would use a List<CPolicyDoc>

This article has been dead for over six months. Start a new discussion instead.