Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello,

look im new in programming, would be awesome if u could help me.

Im reading a whole .csv File with this:


C#
private void button3_Click(object sender, EventArgs e)
        {
            {
                var content = string.Empty;
                using (StreamReader reader = new StreamReader(@"C:/1.csv", System.Text.Encoding.Default))
                {
                    content = reader.ReadToEnd();
                    reader.Close();
                }

                content = content.Replace("\"", string.Empty);
                content = content.Replace("               ", "");
               content = content.Replace("             ", "");

                using (StreamWriter writer = new StreamWriter(@"C:/2.csv"))
                {
                    writer.Write(content);
                    writer.Close();
                }
            }
        }




1.CSV Input looks like this:


" 09000";"Catalaog 1";10148;234
" 09001";"Catalaog 2";0;345

2.CSV Outlooks like this:


09000~Catalaog 1~10148~234
09001~Catalaog 2~0~0


I need a rewrite of my Code that the last delimited Columns 10148~234 get calculated.

String must look like this at the end:

09000~Catalaog 1~9914~234
09001~Catalaog 2~0~0

See the diffrence? The 10148 - 234 = 9914. The 10148 gets replaced with the result.

Could u rewrite my upper code and help me ?:<</xml>
Posted
Comments
ZurdoDev 4-Apr-13 7:27am    
So, you just need to split on the ~ and subtract the 2 numbers? If so, where are you stuck?

Well you could read the entire txt file with ReadAllLines[^]
The result for this is a list of string or a array of strings per ine in the text file. Then you make use of Split[^]

It should now be a prety straight forword task to split the string on the ";" sign.
 
Share this answer
 
new to this, could u rewrite it for example?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900