如何从文件中提取数据并添加数据。 [英] How to extract data from a file and add the data.
本文介绍了如何从文件中提取数据并添加数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本文件,其中包含a = 10和b = 15等数据。如何提取数据并执行添加操作并在控制台窗口中显示结果c#
我尝试过:
我是c#的初学者所以我不知道如何执行这项任务。
I have a text file which contains data such as a=10 and b=15. how to extract both the data and perform the addition operation and display the results in console window in c#
What I have tried:
I am beginner in c# so i dont know how to perform this task.
推荐答案
如果你有控制权在文件格式上,我建议你把它改成一个更机器可读的(例如XML,JSON,INI
)然后使用什么框架
提供(即序列化)读取/写入数据。
另一方面,如果你不能改变文件格式,那么你必须解析它( .NET Framework正则表达式 [ ^ ]会帮助)以便检索值,然后计算结果,然后用更新的内容写回一个新文件。
If you have control on the file format, I suggest you to change it into a more machine-readable one (e.g.XML, JSON, INI
) and then use what theFramework
provides (i.e. serialization) to read/write the data.
On the other hand, if you cannot change the file format then you have to parse it (.NET Framework Regular Expressions[^] would help) in order to retrieve the values, then compute the results and then write back a new file with the updated content.
这篇关于如何从文件中提取数据并添加数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文