I'm a beginner in programming, and I'm doing a project that requires continously getting an input from the Serial Port. I already used the SerialPort class to retrieve the data and use it in my programm, and now I want to write those same SerialPort values (splitted into array[0]....array[7]) into .CSV
Please, I need help

6 Years
Discussion Span
Last Post by Mitja Bonca

here is a small demo of what you can do:

string[] arrData = new string[5];
            arrData[0] = "This";
            arrData[1] = "is";
            arrData[2] = "a";
            arrData[3] = "Demo";
            arrData[4] = "Test";

            string tempString = "";
            foreach (string str in arrData)
                tempString += str + ",";

            tempString = tempString.Substring(0, tempString.Length - 1); //removing last ','

            System.IO.File.WriteAllText("my.csv", tempString);

Contents of my.csv files:


i hope it helps

Edited by sandeepparekh9: n/a


I would rather suggest you to use generic list<T>. But if you insist uisng string array, you can do it in this way too:

string[] array = new string[7];
//reading port and fill the array!
//then you can do:
string delimiter = ";";
//and write to a file:
string path = @"C\MyFolder\myFile.csv";
System.IO.File.WriteAllText(path, Stirng.Join(delimiter, array));

Thanks, what am actually working on collects inputs from the serial port, and I had to split the values to different arrays. So now, I am able to receive array[0], array[1]...
What I now need to do is to save the values of these arrays to a CSV.


Didnt we show you two example how yucan save the array into *.csv file?
Mine and and sandeepparehk0`s post have these kind of solutions.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.