可以读取文件的配置解析器 [英] Configuration parser that can read a file

查看:53
本文介绍了可以读取文件的配置解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道这里是否有人知道如何实现能够读取ini.file的代码。



用户需要能够编辑ini。文件

解决方案

也许我应该为我讽刺的答案道歉 - 但你确实说过你需要知道这里是否有人知道如何阅读文件 - 几乎每个人都这样做;你没做的是询问如何自己做的指导。



因为我们很多人都是(a)讽刺,(b)不愿意做一个提问者应该为自己做的工作,所以通常很明智地证明在寻求帮助之前,你已经努力为自己解决问题。另外,询问您想要答案的问题。 :)



对你的问题更有帮助的答案是,你应该查看系统中的类的MSDN库。 IO 命名空间。在那里,你会找到文件类,它有一些方法可以让你逐行读取文件。



如果您需要解释数字,真/假值或命名指标值,您还应该在 int 中查看系统命名空间。 float ,(...其他数字类型), bool 枚举类型。它们都有一个 TryParse()方法,您可以使用该方法将值的字符串表示形式安全地转换为可用值。



如果你需要更复杂,你可以使用正则表达式( System.Text.RegularExpressions.Regex ) - 这是非常强大的,但同样很难理解。


对不起,我没有参加调查。


是的,我知道。



您打开文件。逐行读取行,然后关闭文件。



完成工作。 :)

I need to know if anyone here knows how to implement a code that is able to read an ini.file.

The user need to be able to edit the ini. file

解决方案

Perhaps I should apologise for my rather sarcastic answer - but you did say you needed to know whether anyone here knew how to read a file - which almost everyone does; what you didn't do was ask for guidance on how to do it yourself.

Since many of us are (a) given to sarcasm, and (b) reluctant to do the work that a questioner should have done for themselves it's generally wise to demonstrate that you've made an effort to solve your problem for yourself before you seek help. Also, ask the question for which you want the answer. :)

A more helpful answer to your question, then, is that you should look at the MSDN library at the classes in the System.IO namespace. There, you will find the File class, which has methods that allow you to read a file line by line.

If you need to interpret numbers, true/false values, or named indicator values, you should also look in the System namespace at the int, float, (... other number types), bool and Enum types. They all have a TryParse() method that you can use to safely turn the string representation of the value into a usable value.

If you need to be a little more sophisticated, you can use Regular Expressions (System.Text.RegularExpressions.Regex) - which are very powerful, but equally hard to get your mind around.


Sorry, I don't participate in surveys.


Yep, I know.

You open the file. Read the lines one by one, then close the file.

Job done. :)


这篇关于可以读取文件的配置解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆