如何使用StreamWriter在单词之间创建空格

Gha*_*eon 1 c# filestream winforms

我需要在file.txt中构建一个表.实际上,我对如何构建它有一些想法,但我不太确定.我有一些字段和它的值我只需要使用这些字段的名称和它的值构建一个表,如:

========================================
ID     MATRICULATION     NAME
2      696969            Jose
4      969696            Maria
5      123456            Eminem
15     123412            Ghaleon
Run Code Online (Sandbox Code Playgroud)

我该怎么办?我猜它正在使用,StreamWriter但我不知道如何制作空格,因为只使用空格键不起作用.

Ser*_*kiy 7

在将字符串写入文件时使用格式:

writer.WriteLine("{0,-10}{1,-15}{2}", id, matriculation, name);
Run Code Online (Sandbox Code Playgroud)

格式语法如下:

{index[,length][:formatString]}
Run Code Online (Sandbox Code Playgroud)

length是参数的字符串表示形式中的最小字符数.如果为正,则参数右对齐; 如果为负数,则为左对齐