0

I write some data into csv file from List but some list indexes has empty string but another indexes has value in these cases the data compared with another list wrote in the same csv file
this is my csv file opened using excel sheet
T
in the third column there exist ID for the the second column cell so in the coming rows i want to detect the name of the ID based on previous rows

like in row 3 it's ID is 19 and name is I/O so in the 7th row the ID is 19 and want to fill the second cell now
info : the IDs is already known above and any next ID will be exist before by the follwing code.

bool isInList = ms.IndexOf(ShapeMaster) != -1; 
if (isInList) 
{ 
    savinglabelnamefortextbox = t.InnerText; 
     string replacement = 
     Regex.Replace(savinglabelnamefortextbox,  @"\t|\n|,|\r", ""); 
    xl.Add("");
    dl.Add(replacement); 
    ms.Add(ShapeMaster); 
}

and I use the following code to write to the csv file

using (StreamWriter sw = File.CreateText(csvfilename))
{ 
    for (int i = 0; i < dl.Count; i++) 
    { 
        var line = String.Format("{0},{1},{2}", dl[i], xl[i],ms[i]); 
        sw.WriteLine(line);
    } 
}
1
  • 1
    What's the question? Are you just trying to put the value from row 3 column 2 (I/O) into every Column 2 where Column 3 is 19 AND Column 2 is empty? Commented Sep 9, 2015 at 17:42

1 Answer 1

1

Try this

            for (int x = 0; x < ms.Count; x++)
        {
            if (xl[x] != "")
            {
                continue;
            }
            else if (xl[x] == "")
            {
                for (int y = 0; y<xl.Count; y++)
                {
                    if (ms[y] == ms[x])
                    {
                        xl[x] = xl[y];
                        break;
                    }
                }
                continue;
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.