Hey guys, I can only apologise for asking such a noob question, but this is the second time today I'm going to be relying on this awesome forum :)
I have a string that is made up of values from an array, taken from an excel sheet, only some of these values are blank. I'm outputting these values to a CSV file, but don't want the blank values to output, these values are outputting as commas, and so are giving me extra lines in my CSV file.
Anyway, here's my code, I want to compare the array values separately to not equal "" before I add them to the string. If this is not possible, I am thinking that I could split the string, compare, and then rejoin it.
enter code here//Get a range of data.
range = objSheet.get_Range(ranges1, ranges2);
//Retrieve the data from the range.
Object[,] saRet;
saRet = (System.Object[,])range.get_Value(Missing.Value);
//Determine the dimensions of the array.
long iRows;
long iCols;
iRows = saRet.GetUpperBound(0);
iCols = saRet.GetUpperBound(1);
//Build a string that contains the data of the array.
String valueString;
valueString = "";
System.IO.StreamWriter OutWrite = new System.IO.StreamWriter("h:\\out.csv");
for (long rowCounter = 1; rowCounter <= iRows; rowCounter++)
{
for (long colCounter = 1; colCounter <= iCols; colCounter++)
{
//Write the next value into the string.
valueString = String.Concat(valueString, Convert.ToString(saRet[rowCounter, colCounter]) + ", ");
}
//Write in a new line.
{
valueString = String.Concat(valueString, "\n");
}
}
//Report the value of the array.
MessageBox.Show(valueString, "Array Values");
OutWrite.WriteLine(valueString);
OutWrite.Close();
OutWrite.Dispose();
}
Cheers, and thanks for your patience!
Andy.