
正文
vb.net文本处理,vb读文本文件
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
VB.net如何读取文本文档的每一行 并把每一行的数据放到对应的文本框中?
Dim AllLine As String() = File.ReadAllLines("Mytxt.txt")
For i = 0 To AllLine.length-1
textBox1.Text = textBox1.Text AllLine(i) vbCrlf
Next
相关问答
Q1: VB.net 读取文本文件?
1、实现上传按钮方法代码。
2、判断图片对象是否为空代码。
3、取得数据库字段 dt.Rows(0)("Pic")方法代码。
4、字节数组转换为Image类型方法代码。
5、处理SQL中操作Image类型方法代码。
6、实现的上传结果。
Q2: vb.net中,如何删除指定文本文档中的指定行的内容
Dim newfile As New List(Of String)
For Each line As String In System.IO.File.ReadAllLines("TextFile1.txt")
If Not line.StartsWith("3") Then newfile.Add(line)
Next
System.IO.File.WriteAllLines("TextFile1.txt", newfile)
建个集合,用System.IO.File的ReadAllLines读出所有内容,逐个判断,如果是需要的加入集合,如果是要删除的什么都不做,最后用WriteAllLines写入即可。
这里说明一下,上面那个代码是用来删除所有以3开头的文本行。
Q3: VB.NET文本框中的文本格式进行相应的设置
太晚了,想不出什么好方法了。
发上来看看吧。
首先建立一个TextBox,我这里名字为TextBox2
然后放一个groupbox,在里头放两个Checkbox,checkbox1为粗体,checkbox2为斜体。
代码:
Dim Bold As Boolean
Dim Italic As Boolean
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
Bold = True
If Italic Then
TextBox2.Font = New Font(TextBox2.Font, FontStyle.Bold Or FontStyle.Italic)
Else
TextBox2.Font = New Font(TextBox2.Font, FontStyle.Bold)
End If
Else
Bold = False
If Italic Then
TextBox2.Font = New Font(TextBox2.Font, FontStyle.Italic)
Else
TextBox2.Font = New Font(TextBox2.Font, 0)
End If
End If
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.Checked Then
Italic = True
If Bold Then
TextBox2.Font = New Font(TextBox2.Font, FontStyle.Italic Or FontStyle.Bold)
Else
TextBox2.Font = New Font(TextBox2.Font, FontStyle.Italic)
End If
Else
Italic = False
If Bold Then
TextBox2.Font = New Font(TextBox2.Font, FontStyle.Bold)
Else
TextBox2.Font = New Font(TextBox2.Font, 0)
End If
End If
End Sub
可以等等别人回答,看看有没有更好的方法。
Q4: vb.net怎么从文本文档中读取一行数据,将文本输出到控制台?
以下示例一次从文件中读取一行,然后将每行文本打印到控制台。
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
Q5: vb.net处理的文本文件为什么会出现小方格大神们帮帮忙
呵,换行符的问题 我以前出现几次这问题了 好象把chr(10)和chr(13)分别替换了,并换成vbcrlf就行啦








