我有以下值(value)观
A = 1,
B = (NULL of 7 characters),
C = denimRocks ,
D = Yes789,
E = (NULL of 2 characters),
F = ATR.
我想将它们写入文本文件的一行,A 从该行的位置 1 开始。B 从位置 2 开始,C 从位置 8 开始,依此类推。
我想显示空值的空格。 我尝试使用 Streamwriter,但无法实现我想要做的事情。
请帮忙。
最佳答案
尝试这样:
string a=string.Empty;
StreamWriter yourStream = null;
protected void Page_Load(object sender, EventArgs e)
{
yourStream = File.CreateText("D:\\test1.txt"); // creating file
a = String.Format("|{0,1}|{1,2}|{2,7}|......", "A", "B", "",......); //formatting text based on poeition
yourStream.Write(a+"\r\n");
yourStream.Close();
}
关于c# - 写入文本文件 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19158295/