如何按类别将settings.ini加载到字符串中。 [英] How to load settings.ini into strings by category.
本文介绍了如何按类别将settings.ini加载到字符串中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我一直在烦恼,因为这无法找到一个简单的解决方案,我的所有代码都变得太乱了。
所以我想要听取你的帮助。
我有一个设置文件,其中包含不同类似的catogorys:
Hey, I've been bothering a little with this can't see to find a simple solution, all my codes get too messy.
So I want to hear you out for help.
I have a settings file with different catogorys like this:
[CATOGORY1]
settings here.
[CATOGORY2]
settings here.
[CATOGORY3]
settings here.
[CATOGORY4]
settings here.
我想在读取文件时将它们分成4个字符串:
Dim catogory1 as String =
Dim catogory2 as String =
Dim catogory3 as String =
Dim catogory4 as String =
有什么可以帮我的吗?
I want to sperate them into 4 strings when reading the file like:
Dim catogory1 as String =
Dim catogory2 as String =
Dim catogory3 as String =
Dim catogory4 as String =
Can any help me with this?
推荐答案
看看这个:< a href =http://www.codeproject.com/Articles/21896/INI-Reader-Writer-Class-for-C-VB-NET-and-VBScript>用于C#,VB.NET的INI读写器类和VBScript [ ^ ]它提供了一些功能来读取部分名称(在您的示例中为CATOGORY1等),并读取部分中的所有键。
阅读部分名称,阅读所有键,然后使用您想要的任何分隔符或格式构建字符串!
Have a look at this: INI Reader / Writer Class for C#, VB.NET, and VBScript[^] It provides fuctions to read the section names ("CATOGORY1", etc. in your example), and to read all the keys within a section.
Read the section names, read all the keys, and you can build your strings with any separator or format you want!
发现这个解决方案很简单:
Found this solution so simple:
<DllImport("kernel32")> _
Private Shared Function GetPrivateProfileString(ByVal Section As String, ByVal Key As String, ByVal [Default] As String, ByVal RetVal As StringBuilder, ByVal Size As Integer, ByVal FilePath As String) As Integer
End Function
Public Function Read(ByVal Key As String, Optional ByVal Section As String = Nothing) As String
Dim RetVal = New StringBuilder(255)
GetPrivateProfileString(Section, Key, "", RetVal, 255, Path)
Return RetVal.ToString()
End Function
这篇关于如何按类别将settings.ini加载到字符串中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文