Ini文件 - 阅读多行? [英] Ini Files - Read Multi Lines?
问题描述
保存时说我的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屋!