从文件夹位置逐个读取.dat文件,修改它们并使用C#代码写入同一文件 [英] Read .dat files one by one from a folder location, modify them and write to the same file using C# code
问题描述
嗨
我是C#的新手(到目前为止还没有编码)。我的要求是逐个从共享文件夹中提取10个.dat文件并验证它们。验证过程包括:
1.在第1行,第2行和文件末尾查找丢失的波浪号(〜)。如果丢失,请添加波浪号(〜)。
2.在文件末尾查找额外的回车并将其删除。
3.在第1行,第2行和文件末尾寻找额外的波浪号(〜)。如果有额外的,请删除波浪号(〜)。
4.完成上述验证后。回写同一个文件并将其保存在同一位置。
我们非常感谢您提供的任何帮助。
谢谢
我尝试过:
我我是一个全新的编码和谷歌搜索,但我无法将各个部分整合在一起。示例代码非常有用。
Hi
I am new to C#(not done any coding till now). My requirement is to pull 10 .dat files from a shared folder one by one and validate them. The validation process includes:
1. Look for missing tilde(~) at line 1, 2, and end of file. Add a tilde(~) if it is missing.
2. Look for extra carriage return at end of file and remove it.
3. Look for extra tilde(~) at line 1, 2, and end of file. Remove tilde(~) if extra is present.
4. After making above validations. Write back to same file and save it in the same location.
Any help in this regard is highly appreciated.
Thanks
What I have tried:
I am totally new to coding and have googled regarding this but I am not able to integrate the pieces together. Sample code would be really helpful.
推荐答案
它不是那样的工作:我们不是来为你做你的工作。
所以先把它分成小任务:
1)读取文件
2)处理文件
3)写文件
1和3应该是微不足道的 - 任何对C#有基本把握的人都应该能够使用File.ReadAllLines和File.WriteAllLines而不需要任何问题。
2)更复杂但不多。
1)看第一行。它是以'〜'开头的吗?没有?添加一个。
2)重复第2行
3)在文件末尾做同样的事情。
有什么复杂的?
It doesn't quite work like that: we aren't here to do your work for you.
So start by breaking it into smaller tasks:
1) Read file
2) Process file
3) Write file
1 and 3 should be trivial - anyone with a basic grasp of C# should be able to use File.ReadAllLines and File.WriteAllLines without any problems.
2) Is more complex, but not much.
1) Look at line one. Does it start with a '~'? No? Add one.
2) Repeat for line 2
3) Do much the same for the end of the file.
What in there is complicated?
这个网站不是免费服务请求的代码。
This site is not a code on request for free service.
我是新手编码
主要有两种解决方案:
- 你有时间,你学习编程。这是一份工作,你无法在几小时内学会它。
- 你很匆忙,而且你雇用了一名专业的程序员。
自由职业者&在线查找自由职业者 - 自由职业者 [ ^ ]
这篇关于从文件夹位置逐个读取.dat文件,修改它们并使用C#代码写入同一文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!