vb.net 读取txt文件内容 字符串类型
————————————————————————————p=""DimpassAsNewStreamReader("C:\Windows\system32\Passwor...
————————————————————————————
p = ""
Dim pass As New StreamReader("C:\Windows\system32\Password.txt", System.Text.Encoding.Default)
Do Until pass.Peek < 0
p += pass.ReadLine + vbCrLf
Loop
pass.Close()
————————————————————————————————
请问 p 的字符串类型是什么类型的?
怎样 让 textbox1.text = p (p即为上部分代码的p 、有英文与数字 ,textbox1.text 表面上看起来与 p 相同 ,但却不相等) 展开
p = ""
Dim pass As New StreamReader("C:\Windows\system32\Password.txt", System.Text.Encoding.Default)
Do Until pass.Peek < 0
p += pass.ReadLine + vbCrLf
Loop
pass.Close()
————————————————————————————————
请问 p 的字符串类型是什么类型的?
怎样 让 textbox1.text = p (p即为上部分代码的p 、有英文与数字 ,textbox1.text 表面上看起来与 p 相同 ,但却不相等) 展开
2个回答
展开全部
刚刚试了一下你的代码,你用的 p += pass.ReadLine + vbCrLf,P是Password.txt里所有的字符串连起来,每行加个换行符,相当于原来那个文本文档里的所有内容,如果 p = pass.ReadLine + vbCrLf 就是循环逐行读取,比较两个字符串是否想等可以用 String.Equals(字符串1,字符串2)
追问
我设定的password.txt只有1行 所以我把+vbcrlf去掉了 那样就不会出现不等于的情况了
但我想问下怎样 用代码去掉换行字符呢
追答
可以直接用Replace函数替换掉换行符
Dim q As String = Replace(p, vbCrLf, "")
展开全部
ate Sub Command1_Click()
Dim item, n As Integer, i As Integer
Dim array1(), array2()
Open "d:\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, item
i = InStr(item, " ")
ReDim Preserve array1(n)
ReDim Preserve array2(n)
array1(n) = Left(item, i - 1)
Print array1(n),
array2(n) = Right(item, Len(item) - i)
Print array2(n)
n = n + 1
Print
Loop
Close
End Sub
///////////////////////////////////////////////////////////////////////////////////
如果你的文本组后有空行,可能会造成下标越界,因此需要把最后的空行的vbcrlf字符替换掉,再去掉,综合代码如下,若有不明白的,可以ps我:
Option Explicit
Private Sub Command1_Click()
Dim s() As String, t() As String, a() As String, b() As String
Dim i As Integer, item, x
Open "D:\1.txt" For Input As #1
x = StrConv(InputB(LOF(1), 1), vbUnicode)
x = Replace(x, " ", ",")
x = Replace(x, vbCrLf, " ")'反复替换,去掉最后的空行
x = Trim(x)
x = Replace(x, " ", vbCrLf)
s = Split(x, vbCrLf)
Close
ReDim a(UBound(s)), b(UBound(s))
For i = 0 To UBound(s)
t = Split(s(i), ",")
a(i) = t(0)
Print a(i)
b(i) = t(1)
Print b(i)
Next
End Sub
Dim item, n As Integer, i As Integer
Dim array1(), array2()
Open "d:\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, item
i = InStr(item, " ")
ReDim Preserve array1(n)
ReDim Preserve array2(n)
array1(n) = Left(item, i - 1)
Print array1(n),
array2(n) = Right(item, Len(item) - i)
Print array2(n)
n = n + 1
Loop
Close
End Sub
///////////////////////////////////////////////////////////////////////////////////
如果你的文本组后有空行,可能会造成下标越界,因此需要把最后的空行的vbcrlf字符替换掉,再去掉,综合代码如下,若有不明白的,可以ps我:
Option Explicit
Private Sub Command1_Click()
Dim s() As String, t() As String, a() As String, b() As String
Dim i As Integer, item, x
Open "D:\1.txt" For Input As #1
x = StrConv(InputB(LOF(1), 1), vbUnicode)
x = Replace(x, " ", ",")
x = Replace(x, vbCrLf, " ")'反复替换,去掉最后的空行
x = Trim(x)
x = Replace(x, " ", vbCrLf)
s = Split(x, vbCrLf)
Close
ReDim a(UBound(s)), b(UBound(s))
For i = 0 To UBound(s)
t = Split(s(i), ",")
a(i) = t(0)
Print a(i)
b(i) = t(1)
Print b(i)
Next
End Sub
追问
这个是VB6.0的代码吧
我那个是vb.net
现在是编写一个关于密码的程序
但读取出带有英文的txt 文本后 在textbox1中输入相同的英文 却不等
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询