VB.NET怎么删除INI文件里的一个字段或键值?1vb.net操作ini,对于INI文件,可以当做像TXT文件一样来进行读取和写入 。
2,先把整个文件度出来 , 然后找到相应行删除(抛弃)以后 , 再重新写入文件 。
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyStr As String = ""
Dim AllStr As String = ""
'获取一个可用vb.net操作ini的文件号
Dim MyFileNum As Integer = FreeFile()
'打开指定vb.net操作ini的文件,进行读取操作
FileOpen(MyFileNum, "C:\My.ini", OpenMode.Input)
Do While Not EOF(MyFileNum)
'读取一行
MyStr = LineInput(MyFileNum)
If MyStr"b=2" Then
If AllStr = "" Then
AllStr = AllStrMyStr
Else
AllStr = AllStrvbCrLfMyStr
End If
End If
Loop
FileClose(MyFileNum)'关闭文件
'写文件
Dim MyStream As New System.IO.FileStream("C:\My.ini", IO.FileMode.Create)
Dim MyWriter As New System.IO.StreamWriter(MyStream, System.Text.Encoding.UTF8)
MyWriter.WriteLine(AllStr)
MyWriter.Flush()
MyWriter.Close()
MyStream.Close()
End Sub
End Class
VB.net2005中到底怎么读取ini文件用API吧
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32
'读
Public Function GetINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As String
Dim Str As String = LSet(Str, 256)
GetPrivateProfileString(Section, AppName, lpDefault, Str, Len(Str), FileName)
Return Microsoft.VisualBasic.Left(Str, InStr(Str, Chr(0)) - 1)
End Function
'写
Public Function WriteINI(ByVal Section As String, ByVal AppName As String, ByVal WriteString As String, ByVal FileName As String) As Long
WriteINI = WritePrivateProfileString(Section, AppName, WriteString, FileName)
End Function
其中,Section是像[ip]那样的(填里面的就可以了) , AppName是“=”前面的项名称,lpDefault是如果没有可用的值,就返回lpDefault,FileName是文件名,WriteString是要写入的值
你所希望的:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(GetINI("ip", "user_id", "", "D:\DataBase.ini"))
'返回sa
End Sub
vb.net ini操作名字有规律,就可以for循环 。
名字没有规律,可以想办法让他有规律,一种方法是设置包含所有节名称的string数组,再循环 。
【vb.net操作ini vbnet invoke】vb.net操作ini的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vbnet invoke、vb.net操作ini的信息别忘了在本站进行查找喔 。
推荐阅读
- 直播摄像头软件,专业直播摄像头
- 怎么下载音乐到u盘,酷狗怎么下载音乐到u盘
- iphone好玩的格斗游戏,苹果好玩的格斗游戏
- js调用本地播放器播放视频,js播放本地音乐
- php发送tcp数据报 php发送socket
- 硬盘文件怎么保存时间长,硬盘怎么保存它不容易坏
- 益智动画片小熊钓鱼游戏,小熊钓鱼看图写话图片
- 小行网络游戏,网络小游戏排行
- mysql怎么增加权限 mysql 增加用户