vb.net设置文件修改 vb如何修改文件内容
vb.Net对文件指定字符串的修改
文本框 TextBox1
成都创新互联公司主要为客户提供服务项目涵盖了网页视觉设计、VI标志设计、网络营销推广、网站程序开发、HTML5响应式网站建设公司、移动网站建设、微商城、网站托管及企业网站维护、WEB系统开发、域名注册、国内外服务器租用、视频、平面设计、SEO优化排名。设计、前端、后端三个建站步骤的完善服务体系。一人跟踪测试的建站服务标准。已经为社区文化墙行业客户提供了网站维护服务。
上一条 Button1
下一条 Button2
修改 Button3
Imports System.IO
Public Class Form1
Dim currIndex As Integer = 0
Dim s2 As List(Of String) = New List(Of String)
Dim s As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
s = File.ReadAllText(Application.StartupPath "\txt.txt")
Dim s1 As String() = s.Split("@")
For i As Integer = 0 To s1.Length - 1
If s1(i).Trim() "" Then
s2.Add("@" s1(i))
End If
Next
TextBox1.Text = s2(0)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
currIndex = currIndex + 1
If currIndex s2.Count - 1 Then
MsgBox("已经是最后条了")
Return
End If
TextBox1.Text = s2(currIndex)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
currIndex = currIndex - 1
If currIndex 0 Then
MsgBox("已经是第一条了")
Return
End If
TextBox1.Text = s2(currIndex)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
s2(currIndex) = TextBox1.Text
s = ""
For i As Integer = 0 To s2.Count - 1
s = s2(i)
Next
File.WriteAllText(Application.StartupPath "\txt.txt", s)
End Sub
End Class
VB.NET修改txt文件指定行?
For Example:
1.txt文件内容如下:
The 1st line.
#The 2nd line.
The 3rd line.
The 4th line.
.
修改第二行内容,将#除去.修改后的文本如下:
The 1st line.
The 2nd line.
The 3rd line.
The 4th line.
1 输入方式打开原文件 1.txt;
2 输出方式打开新文件 2.txt;
3 逐行 Line Input 从 1.txt 中读数据,Print 写入 2.txt,直至要修改的行;
4 丢弃从 1.txt中读出的要修改的行,将新内容行写入 2.txt;
5 仿照第 3 步,将其余的行从 1.txt 复制到 2.txt。
6 关闭两个文件
7 删除1.txt,将 2.txt 的文件名改为原来 1.txt 的。
VB.net如何提取system并修改文件安全属性?
将以下代码保存到模块中:
Declare Function GetPrivateProfileString Lib "kernel32" Alias _
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileStringByKeyName Lib "kernel32" Alias _
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpString As String, _
Public Function GetIniParam(NomFichier As String, NomSection As String, NomVariable As String) As String
Dim ReadString As String * 255
Dim returnv As String
Dim mResultLen As Integer
mResultLen = GetPrivateProfileString(NomSection, NomVariable, "(Unassigned)", ReadString, Len(ReadString) - 1, NomFichier)
If IsNull(ReadString) Or Left$(ReadString, 12) = "(Unassigned)" Then
Dim Tempvalue As Variant
Dim Message As String
Message = "配置文件 " NomFichier " 不存在."
returnv = ""
Else
returnv = Left$(ReadString, InStr(ReadString, Chr$(0)) - 1)
End If
GetIniParam = returnv
End Function
Public Function WriteWinIniParam(NomDuIni As String, sLaSection As String, sNouvelleCle As String, sNouvelleValeur As String)
Dim iSucccess As Integer
iSucccess = WritePrivateProfileStringByKeyName(sLaSection, sNouvelleCle, sNouvelleValeur, NomDuIni)
If iSucccess = 0 Then
WriteWinIniParam = False
Else
WriteWinIniParam = True
End If
End Function
调用方法:
Call WriteWinIniParam(App.Path "\LiveUpdate.ini", "LiveUpdate", "AppName", txtAppName.Text)
txtFile.Text = GetIniParam(App.Path "\LiveUpdate.ini", "LiveUpdate", "FILES1")
vb.net中在指定文件的行修改内容?
用替换函数直接把03-24^32替换为03-24^xx(想替换的值)。
比如,你的文本放在TextBox1文本框的话,用下面的指令替换就可以了。
Dim txt As String = TextBox1.Text
TextBox1.Text = Replace(txt, "03-24^32", "03-24^xx")
执行上面替换指令后,TextBox1的文本替换为:
【例如:03-23^23
03-24^xx
我要指定修改第二行的32.该怎么办?】
VB.NET中,文件对话框(OpenFileDialog)显示某种设定的文件类型需要修改什么属性?
Filter 属性设置当前文件名筛选字符串,该字符串确定出现在对话框的“文件类型”框中的选项。
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 1 ; // 获取或设置文件对话框中当前选定筛选器的索引;
openFileDialog1.RestoreDirectory = true ;
对于每个筛选选项,筛选器字符串都包含筛选器说明,后接一垂直线条 (|) 和筛选器模式。不同筛选选项的字符串由垂直线条隔开。
文章名称:vb.net设置文件修改 vb如何修改文件内容
文章来源:http://myzitong.com/article/hidjpo.html