新聞中心
VB.NET修改txt文件指定行?
For Example:
創(chuàng)新互聯(lián)建站主營平房網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,手機(jī)APP定制開發(fā),平房h5微信平臺小程序開發(fā)搭建,平房網(wǎng)站營銷推廣歡迎平房等地區(qū)企業(yè)咨詢
1.txt文件內(nèi)容如下:
The 1st line.
#The 2nd line.
The 3rd line.
The 4th line.
.
修改第二行內(nèi)容,將#除去.修改后的文本如下:
The 1st line.
The 2nd line.
The 3rd line.
The 4th line.
1 輸入方式打開原文件 1.txt;
2 輸出方式打開新文件 2.txt;
3 逐行 Line Input 從 1.txt 中讀數(shù)據(jù),Print 寫入 2.txt,直至要修改的行;
4 丟棄從 1.txt中讀出的要修改的行,將新內(nèi)容行寫入 2.txt;
5 仿照第 3 步,將其余的行從 1.txt 復(fù)制到 2.txt。
6 關(guān)閉兩個文件
7 刪除1.txt,將 2.txt 的文件名改為原來 1.txt 的。
vb.net怎么從文本文檔中讀取一行數(shù)據(jù),將文本輸出到控制臺?
以下示例一次從文件中讀取一行,然后將每行文本打印到控制臺。
Sub ReadTextLinesFromFile()
Dim file As New System.IO.StreamReader("c:test.txt")
Dim oneLine As String
oneLine = file.ReadLine()
While (oneLine "")
Console.WriteLine(oneLine)
oneLine = file.ReadLine()
End While
file.Close()
End Sub
VB.NET讀取TXT文件數(shù)據(jù)保存為數(shù)組
VB.NET編程讀取txt文本文檔中的數(shù)據(jù),并把數(shù)據(jù)保存為數(shù)組,代碼如下:
'寫配件文件
Private?Sub?saveIni(ByVal?filePath?As?String,?ByVal?str?As?String)
Dim?sw?As?StreamWriter?=?New?StreamWriter(filePath,?True)?'true是指以追加的方式打開指定文件
sw.WriteLine(str)
sw.Flush()
sw.Close()
sw?=?Nothing
End?Sub
'讀配件文件
Private?Function?readIni(ByVal?filePath?As?String)
Dim?iniDt?As?New?DataTable
iniDt.Columns.Add("text")
iniDt.Columns.Add("value")
Try
Dim?sr?As?StreamReader?=?New?StreamReader(filePath,?System.Text.Encoding.Default)
Dim?line?As?String?=?""
While?Not?sr.EndOfStream
Dim?str?=?sr.ReadLine()'讀取當(dāng)前行
iniDt.Rows.Add(New?String()?{
str(0),
str(1)
})
End?While
sr.Close()
sr?=?Nothing
Catch?ex?As?Exception
End?Try
Return?iniDt
End?Function
VB.net窗體設(shè)計中,如何讀取.txt文件中的數(shù)據(jù)?
1、新建一個標(biāo)準(zhǔn)的VB EXE工程,只有一個Form,F(xiàn)orm上有兩個按鈕:Command1和Command2。
2、雙擊Command1添加如下代碼
Private Sub Command1_Click()
Dim strFile? ? ?As String
Dim intFile? ? ?As Integer
Dim strData? ? ?As String
strFile = "c:\學(xué)生成績.txt"
intFile = FreeFile
Open strFile For Input As intFile
strData = StrConv(InputB(FileLen(strFile), intFile), vbUnicode)
Debug.Print strData
Close intFile
End Sub
3、按F8開始單步調(diào)試代碼,點擊Command1,進(jìn)入單步調(diào)試功能,
4、多次按下F8或直接按下F5運行完成,就完成了讀取文本文件內(nèi)容并輸出到立即窗口。
vb.net報表設(shè)置記錄行數(shù)
Visualbasic代碼編輯器沒有這個功能,但可以用第三方的編輯軟件Emedit來實現(xiàn)這個功能。
1、用Emedit打開*.frm文件。
2、點工具,當(dāng)前配置屬性,然后勾選顯示行號即可。
當(dāng)前名稱:vb.net文件行數(shù)據(jù)的簡單介紹
文章路徑:http://www.dlmjj.cn/article/dsgeohp.html