如何解析INI文件? [英] how to parse INI files ?

查看:98
本文介绍了如何解析INI文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我希望我的程序能够解析INI文件,只知道怎么做

,但是,希望你们可以对此有所了解,比如。


例如:


[配置]


admin = dreamcatcher

[变量]


var1 = 100

var2 =" string literal"


var3 = 0x4234

var4 = 1010101010101

[adapter]


vga = Super VGA

-

发表于 http://dbforums.com

解决方案



使用GetPrivateProfileString API


dreamcatcher写道:


我希望我的程序解析INI文件,只知道怎么做的
但是,希望你们可以对此有所了解,比如。
例如:
[co nfiguration]
admin = dreamcatcher
[变量]
var1 = 100
var2 =" string literal"
var3 = 0x4234
var4 = 1010101010101
[适配器]
vga =超级VGA




(无情地剥离空白)


好​​的,就像你一样可以看到,这里有一种语法。让我们看看我是怎么做的:


INI文件:

部分

部分INI文件


部分:

section-title var-list

section-title:

'' [''section-identifier'']''


section-identifier:

a字符序列不包括'']''


var-list:

var-value-pair

var-value-pair var-list

var-value-pair:

变量''=''价值


变量:

a不包括的字符序列''=''


值:

a以换行符结尾的字符序列


我想我做对了。实现那种语言,你笑了。


-

Richard Heathfield: bi **** @ eton.powernet.co.uk

Usenet是一个奇怪的地方。 - Dennis M Ritchie,1999年7月29日。

C FAQ: http://www.eskimo.com/~scs/C-faq/top.html

K& R答案,C书等:< a rel =nofollowhref =http://users.powernet.co.uk/etontarget =_ blank> http://users.powernet.co.uk/eton


jacob navia写道:


使用GetPrivateProfileString API




C中没有这样的功能或API。


-

Richard Heathfield: bi **** @ eton.powernet.co.uk

Usenet是一个奇怪的地方。 - Dennis M Ritchie,1999年7月29日。

C FAQ: http://www.eskimo.com/~scs/C-faq/top.html

K& R答案,C书等:< a rel =nofollowhref =http://users.powernet.co.uk/etontarget =_ blank> http://users.powernet.co.uk/eton



I want my program to parse INI files, only have little clue of how to do
that, though, hope you guys might shed some light on this, thanx.

for example:

[configuration]

admin=dreamcatcher

[variables]

var1=100

var2="string literal"

var3=0x4234

var4=1010101010101

[adaptor]

vga=Super VGA
--
Posted via http://dbforums.com

解决方案


Use the GetPrivateProfileString API


dreamcatcher wrote:


I want my program to parse INI files, only have little clue of how to do
that, though, hope you guys might shed some light on this, thanx.
for example:
[configuration]
admin=dreamcatcher
[variables]
var1=100
var2="string literal"
var3=0x4234
var4=1010101010101
[adaptor]
vga=Super VGA



(Whitespace stripped mercilessly)

Okay, as you can see, there''s a sort of grammar here. Let''s see how I do:

INI-file:
section
section INI-file

section:
section-title var-list

section-title:
''['' section-identifier '']''

section-identifier:
a sequence of characters not including '']''

var-list:
var-value-pair
var-value-pair var-list

var-value-pair:
variable ''='' value

variable:
a sequence of characters not including ''=''

value:
a sequence of characters terminating in a newline character

I think I got that right. Implement that language, and you''re laughing.

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton


jacob navia wrote:


Use the GetPrivateProfileString API



There is no such function or API in C.

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton


这篇关于如何解析INI文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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