lundi 20 avril 2015

How do i add an empty line before a line only from the second one?

This is the code the variable w is StreamWriter:

var c = GetAll(this, typeof(ComboBox));
foreach (ComboBox cc in c)
{
    if (c.Count() == 1)
    {
        w.Write("ComboBox Name " + cc.Name + Environment.NewLine + Environment.NewLine);
    }
    else
    {
        w.Write(Environment.NewLine + "ComboBox Name " + cc.Name + Environment.NewLine + Environment.NewLine);
    }
    foreach (string ccc in cc.Items)
    {
        w.WriteLine("Classes " + ccc);
        CMBXWMICLASSES.Add(ccc);
    }
}

w.Close();

The problem is in this place:

if (c.Count() == 1)
{
    w.Write("ComboBox Name " + cc.Name + Environment.NewLine + Environment.NewLine);
}
else
{
    w.Write(Environment.NewLine + "ComboBox Name " + cc.Name + Environment.NewLine + Environment.NewLine);
}

What i want is that the first line with ComboBox Name will be with an empty line only after it. For example:

CombBox Name: daniel

something here....after the empty line

And then in the next time where there is ComboBox Name it should add empty lines from both sides:

something here then empty line:

ComboBox Name: sharon

something here after empty line

But what i get is already in the first line that write ComboBox Name an empty line before it.

This is how i see it in the text file:

Empty line

ComboBox Name cmbxOption

Classes Win32_1394Controller Classes Win32_1394ControllerDevice Classes Win32_BaseBoard

ComboBox Name cmbzxfdgdfg

Classes.... Classes.... Classes....

The problem is with the ComboBox cmxOption that there is an empty line before it and it shouldnt be.

Aucun commentaire:

Enregistrer un commentaire