如何在ini文件中读取多行值 [英] How to read multiline values in inifile

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

问题描述

我尝试使用ini文件中列表中指定的多行值,我能够读取节,但无法从给定键读取多行值.

I am trying to use a multi line value as specified as list in ini file, I was able to read sections but not able read to multi line values from a given key.

我试图以列表方式完全失败.

I have tried to using list manner it completely failed.

# Ini file
[UNITS]
COMPARE_UNITS = [list
                    [11871000 118700]
                    [1198100 1198100]
                ]
[VARS]
OLD_REL = 4.3
NEW_REL = 4.5

我也尝试使用基于字符串的格式,但是我失败了,但是我能够读取给定键值的部分和第一行.

I have tried to using string based format also i failed but i could able to read sections and first line of a given key value.

# Ini file
[UNITS]
COMPARE_UNITS = "
                    11871000 118700
                    1198100 1198100
                "
[VARS]
OLD_REL = 4.3
NEW_REL = 4.5

当我尝试获取键值时,它仅返回第一行

When i tried to get key values it returns only first line

% set fileOrg [ini::open "sample.ini" r]
ini11
% foreach sec [ini::sections $fileOrg] {puts [::ini::get $fileOrg $sec]}
NEW_REL 4.5 OLD_REL 4.3
COMPARE_UNITS {1198100 1198100}
%

我有两个问题

  1. 如何使用打包inifile
  2. 从给定的键中读取多值
  3. 我可以在键中指定列表值吗?
  1. How to read a multi value form a given key using package inifile
  2. Can i specify a list values in a key?

-马里

推荐答案

INI文件格式不支持多行值.规范是在方括号中带有节名称以开始新节的行,或者是具有键名后跟等号然后在行尾终止的值的行.或评论行.

The INI file format does not support multiline values. The specification is lines with either a section name in square brackets to start a new section or lines with a keyname followed by an equals sign followed by a value terminated in a line end. Or a comment line.

tcllib解析器将文件分成几行,如果该行不是注释,则不是节开头,并且不包含等号,则将其丢弃.

The tcllib parser splits the file into lines and if the line is not a comment, not a section start and does not contain an equals sign it is discarded.

如果要在INI文件值中包含多个值,则应使用一些特定于应用程序的字段分隔符或多个键,例如:

If you want to include multiple values in an INI file value then you should use some application-specific field separator or multiple keys eg:

[Test.Field]
multi-field = first|second|third
[Test.MultiKey]
multi.1 = first
multi.2 = second
multi.3 = third

第一个版本可以简单地用作:

The first version could be used as simply as:

set ini [ini::open test.ini r]
set fields [split [ini::value $ini Test.Field multi-field] "|"]

这篇关于如何在ini文件中读取多行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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