C# 输出文件未在标头后创建单个间隙

C# 输出文件未在标头后创建单个间隙,c#,string,visual-studio-2010,visual-studio,C#,String,Visual Studio 2010,Visual Studio,我正在使用我的C#应用程序生成一个文本文件,我想知道为什么我的输出在标题行之后没有给我一个单行间隔。嗯,我的输入文本文件确实有这个单行间距,但在转换后,我看不到这个单行间距。请帮帮我 代码片段:- public void just_create_text() { //Here we are exporting header string[] strLines = System.IO.File.ReadAllLines(textBox1.Text); string Caro

我正在使用我的C#应用程序生成一个文本文件,我想知道为什么我的输出在标题行之后没有给我一个单行间隔。嗯,我的输入文本文件确实有这个单行间距,但在转换后,我看不到这个单行间距。请帮帮我

代码片段:-

public void just_create_text()
{
    //Here we are exporting header
    string[] strLines = System.IO.File.ReadAllLines(textBox1.Text);
    string CarouselName = enter.Text;
    int[] cols = new int[] { 15, 15, 25, 15, 15 };
    StringBuilder sb = new StringBuilder();
    string line = RemoveWhiteSpace(strLines[0]).Trim();
    string[] cells = line.Replace("\"", "").Split('\t');

    for (int c = 0; c < cells.Length; c++)
        sb.Append(cells[c].Replace(" ", "_").PadRight(cols[c])); 
     // here i am replacing the space with underscore...

    sb.Append("Location".PadRight(15));
    sb.Append("\r\n");

    int tmpCarousel = 0;
    int carouselNumber = 0;
    Dictionary<string, int> namesForCarousels = new Dictionary<string, int>();
    for (int i = 0; i < textfile.Count; i++)
    {
         for (int c = 0; c < cells.Length; c++)
         sb.Append(textfile[i].Cells[c].Replace(" ","_").PadRight(cols[c]));

        string name = textfile[i].Cells[1];

        if (namesForCarousels.TryGetValue(name, out tmpCarousel) == false)
        {
            carouselNumber++;
            namesForCarousels[name] = carouselNumber;
        }
        var strCorousel = lstMX.Find(x => x.MAX_PN.Equals(name)).Carousel;
        strCorousel = (String.IsNullOrEmpty(strCorousel)) ? CarouselName : strCorousel;
        sb.Append(String.Format("{0}:{1}", strCorousel, carouselNumber).PadRight(15));

        sb.Append("\r\n");
    }
    System.IO.File.WriteAllText(@"D:\output.TXT", sb.ToString());
}

private string RemoveWhiteSpace(string str)
{
    str = str.Replace("  ", " ");
    if (str.Contains("  "))
        str = RemoveWhiteSpace(str);
    return str;
}
在输出文本文件中,我需要如下所示

 Designator     MAX_PN         Footprint                Center-X(mm)   Center-Y(mm)   Location   
                   // <<Here is the single gap>>    
 C66            100-0009       0805M_-_CAPACITOR        90.106         39.37          eeee:1         
 C24            100-0009       0805M_-_CAPACITOR        64.973         24.067         eeee:1         
 C25            100-0009       0805M_-_CAPACITOR        106.553        45.657         eeee:1   
指示器最大PN封装外形中心-X(mm)中心-Y(mm)位置
//     
C66 100-0009 0805M电容器90.106 39.37 eeee:1
C24 100-0009 0805M电容器64.973 24.067 eeee:1
C25 100-0009 0805M电容器106.553 45.657 eeee:1

我不知道你为什么一开始就认为会得到一个空行。但请尝试在此处向输出中添加另一行:

sb.Append("Location".PadRight(15));
sb.Append("\r\n");
sb.Append("\r\n");
更好的方法是使用sb.AppendLine()方法:

sb.AppendLine("Location".PadRight(15));
sb.AppendLine();
也看看这个和这个过去:-请
sb.AppendLine("Location".PadRight(15));
sb.AppendLine();