c# - 写入文本文件 C#

标签 c# asp.net text-files fixed-length-record

我有以下值(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/

相关文章:

c# - Windows 10平板模式关闭win窗体应用后返回开始菜单

asp.net - 如何将 2 个日历彼此相邻而不是彼此放置?

java - 如何将 java 控制台输出中的所有 java 行保存到文本文件并正确附加它?

php - 如何使用 PHP 从文本文件(数组)中选择一个随机单词?

c# - 使用 Roslyn 创建诊断分析器时缺少包

c# - 如何访问FlipView内DataTemplate内的xaml控件

c# - UnitOfWork类的结构图及生命周期

asp.net - SharePoint - 使用 ASP 获取登录用户,使用 javascript 进行操作?

asp.net - 如何从 .aspx 页面检索查询字符串值并将其传递到 ascx 页面

C电话本程序: Reposition cursor in text file to start of previous line