Ini文件 - 阅读多行? [英] Ini Files - Read Multi Lines?

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

问题描述

我知道Ini文件是针对单行信息的,不用说我正在尝试从Ini读取/写入多行数据 - 没有太多的成功(我一直似乎都在努力地做事情!)



保存时说我的Ini文件如下所示:

  [richardmarx] 
文件名=危险
夜晚的孩子
在这里等待

假设Ini文件是动态构建的(即,richardmarx和文件名不知道,但唯一的 - 它们可以是任何东西)。



我可以读取Ini文件吗?



在这个例子中,我如何将richardmarx放入TEdit,以及与richardmarx部分关联的文件名为备忘录?



非常感谢提前。

解决方案

线串入INI文件开头。像@RobertFrank建议的那样逃避换行。我不会使用asterik,但是,这是一个有效的文本字符。我会使用这样的东西:

  [richardmarx] 
文件名=危险%nchildren的夜晚%nright这里等待

然后,您可以阅读字符串并替换%n 序列,其值为 sLineBreak 全局变量。如果您需要存储实际的字符,请将其转义为 %% ,例如:

  [sales] 
value = Sale! 50 %% off%nat Macy's


I am aware that Ini Files are meant for single lines of information, needless to say I am trying to read/write multi lines to and from the Ini - without much success (I always seem to do things the hard way!)

Lets say my Ini File when saved, looks like this:

[richardmarx] 
Filenames=hazard
children of the night
right here waiting

Suppose the Ini File is built dynamically (ie, the richardmarx and the Filenames are not know, but unique - they could literally be anything).

How would I be able to read the Ini File?

In this example then, how could I put richardmarx into a TEdit, and the Filenames associated with richardmarx section into a memo?

Many thanks in advance.

解决方案

Do not store multi-line strings into an INI file to begin with. Escape the line breaks, like @RobertFrank suggested. I would not use an asterik for that, though, as that is a valid text character. I would use something like this instead:

[richardmarx] 
Filenames=hazard%nchildren of the night%nright here waiting

You can then read the string and replace the %n sequences with the value of the sLineBreak global variable. If you needed to store an actual % character, escape it as %%, eg:

[sales] 
value=Sale! 50%% off%nat Macy's

这篇关于Ini文件 - 阅读多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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