Ini Files - Read Multi Lines?

后端 未结 8 2196
旧巷少年郎
旧巷少年郎 2020-12-16 03:40

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 alwa

8条回答
  •  抹茶落季
    2020-12-16 04:04

    Pre-process the .ini file! Change all line-breaks between ] and [ to some character that will never appear in a filename (like asterisk). Then use TInifile to access the file you just preprocessed, changing the asterisks back to line breaks after you retrieve the strings. (Use StringReplace)

    It's a little more complicated than that if you have more than one identifier in a section. In that case, you could use the equals sign as a flag that the preceding line break should not be removed. Maybe you read the file from the end towards the beginning.

    You could even create a descendant of TIniFile that did the astrerisk-to-linebreak change for you.

    No, this is certainly not an elegant solution. But, sometimes brute force like this works if you're stuck! The other solutions here are probably better, but thought I'd share this anyway in case it gives you a direction to think about heading...

提交回复
热议问题