Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3306632
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:18:42+00:00 2026-05-17T21:18:42+00:00

Hey guys, I can only apologise for asking such a noob question, but this

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:18:42+00:00Added an answer on May 17, 2026 at 9:18 pm
     public static class ExtensionLib
     {
    
            public static string MyConcat(this string input, params string[] others)
            {
                if (others == null || others.Length == 0)
                   return input;
                string retVal = input??"";
                foreach(string str in others)
                {
                    if (String.IsNullOrEmpty(str))
                        return input;
                    retVal += str;
                }
                return retVal;
            }
     }
    

    and use it as bellow:

    ….

    valueString.MyConcat(arg1, arg2, ...);
    

    Take a care about this line:

    valueString = String.Concat(valueString, Convert.ToString(saRet[rowCounter, colCounter]) + ", ");
    

    instead write

    valueString = valueString.MyConcat(Convert.ToString(saRet[rowCounter, colCounter]), ", ");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, this is simple but I can't make it workn... blah! I have
Hey guys can you help me with this. I've got this '/[^A-Za-z]/' but cannot
Hey guys sorry this is a pretty long question but I cannot call printPASSInfo()
Hey guys i had an idea yesterday. Can you help me with this. Here
hey guys having this really simple problem but cant seem to figure out have
Hey guys, I've been browsing around on SO for quite some time and can't
Hey guys I have enabled APC on my VPS but now I can't access
Hey guys was hoping you can help me out. been at this for like
Hey guys I know that this is probably just a simple sql statement but
Hey guys, first time using stackoverflow. can you guys help me debug? Heres the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.