讀文件內(nèi)容到TextBox :
成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供二道江網(wǎng)站建設(shè)、二道江做網(wǎng)站、二道江網(wǎng)站設(shè)計、二道江網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、二道江企業(yè)網(wǎng)站模板建站服務(wù),10年二道江做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
Try
Using sr As StreamReader = New StreamReader("C:\\TestFile.txt")
textbox1.Text = sr.ReadToEnd()
End Using
Catch E As Exception
Console.WriteLine(E.Message)
End Try
修改完成后,保存到文件:
Using sw As StreamWriter = New StreamWriter("C:\\TestFile.txt")
sw.Write(textbox1.Text)
sw.Close()
End Using
其中,流構(gòu)造的參數(shù)
New StreamReader("C:\\TestFile.txt")
New StreamWriter("C:\\TestFile.txt")
中的"C:\\TestFile.txt"可以用OpenFileDialog和SaveFileDialog的FileName屬性替換.
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
Using sr As StreamReader = New StreamReader(openFileDialog1.FileName)
textbox1.Text = sr.ReadToEnd()
End Using
Catch E As Exception
Console.WriteLine(E.Message)
End Try
End If
保存的時候換成SaveFileDialog就好
.or Example:
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 復制到 2.txt。
6 關(guān)閉兩個文件
7 刪除1.txt,將 2.txt 的文件名改為原來 1.txt 的。
VB.NET中,基本不使用MsgBox了,改用MessageBox.Show("顯示文本")。
這是系統(tǒng)默認的提示窗口,無法單獨改變字體。
想實現(xiàn)類似一般軟件的關(guān)于窗口,可以單獨設(shè)計創(chuàng)建一個窗體。
網(wǎng)站題目:vb.net文本編輯 vbnet trim
鏈接地址:http://muchs.cn/article32/doecpsc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、全網(wǎng)營銷推廣、網(wǎng)站設(shè)計公司、網(wǎng)站排名、做網(wǎng)站、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)