vb.net INI配置文件读写类(List)

这篇博客介绍了如何使用VB.NET编写一个CIni类,用于读写INI配置文件。通过List结构,实现了对INI文件的解析和保存,包括读取文件到内存、将内存结构保存回文件等功能。
摘要由CSDN通过智能技术生成

学习vb.net,练习写了一个ini文件类,试用List。 

Imports System.IO
Imports System.Text
#Region "配置文件 CIni类定义"
Public Class CIni
    Inherits CSections
    Public Property FullName As String

    Public Sub New(ByVal _IniFullName As String)
        FullName = _IniFullName
        If Dir(_IniFullName) <> "" Then
            ReadFromIni()
        End If
    End Sub

#Region "属性:Path,返回INI文件的路径。"
    Public ReadOnly Property Path As String
        Get
            Dim iIndex As Integer = FullName.Split("\").Last().Length
            Return FullName.Substring(0, FullName.Length - iIndex)
        End Get
    End Property
#End Region

#Region "属性:Name,返回INI短文件名。"
    Public ReadOnly Property Name As String
        Get
            Return FullName.Split("\").Last
        End Get
    End Property
#End Region

#Region "属性:Sections,返回节列表。"
    Public Property Sections As CSections
        Get
            Return Me
        End Get
        Set(ByVal _Sections As CSections)
            For Each s As CSection In _Sections
                Add(s)
            Next
        End Set
    End Property
#End Region

#Region "方法:ReadFromIni,把磁盘INI设置文件读取到内存中。"
    ''' <summary>
    ''' 把List结构的INI文件转换成INI类结构
    ''' </summary>
    ''' <remarks></remarks>
    Private Function ReadFromIni() As Boolean
        '        Dim bRead = True
        Dim listIni As List(Of String) = ReadIniToList()
        If IsNothing(listIni) Then
            Return False
        End If
        Dim strSectionName As String = ""
        Dim strNote As String = ""
        With listIni
            For i As Integer = 0 To .Count - 1
                If .Item(i).First = ";" Then
                    strNote = .Item(i).Substring(1, .Item(i).Length - 1)
                ElseIf .Item(i).First = "[" Then
                    strSectionName = .Item(i).Substring(1, .Item(i).Length - 2)
                    Add(New CSect

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值