16 个解决方案
#1
Replace()
#2
2进制转换为字符串:
dim b() as byte '放2进制的数据
dim v as variant
dim s as string
v=b
s=v
首先将数据转为字符串,然后在用instr、mid等函数慢慢转。
比如:
dim p as long
p=instr(....)
mid$(s,p,3)="ABC" '注意,mid函数可以这么用,当然用replace也可以。
dim b() as byte '放2进制的数据
dim v as variant
dim s as string
v=b
s=v
首先将数据转为字符串,然后在用instr、mid等函数慢慢转。
比如:
dim p as long
p=instr(....)
mid$(s,p,3)="ABC" '注意,mid函数可以这么用,当然用replace也可以。
#3
AresChen(AresChen) :你可能没看清楚,我的问题是必须使用二进制存取模式,用TextBox1中的字符串批量替换e:\abc.bat文件中的某些相同的字符串,不是转换制式,是替换字符串.
#4
如果文件是文本文件的话:
dim buff() as byte
dim l as long
dim filename as string
filename="你的文件路径"
l=filelen(filename)
redim buff(l-1)
open filename for binary as #1
get #1,,buff
close #1
dim s as string
s=strconv(buff,vbunicode)
Replace s, "要替换的内容", text1.Text
kill filename
open filename for binary as #1
put #1,,s
close #1
dim buff() as byte
dim l as long
dim filename as string
filename="你的文件路径"
l=filelen(filename)
redim buff(l-1)
open filename for binary as #1
get #1,,buff
close #1
dim s as string
s=strconv(buff,vbunicode)
Replace s, "要替换的内容", text1.Text
kill filename
open filename for binary as #1
put #1,,s
close #1
#5
rainstormmaster(rainstormmaster) :如果我用一个替换按钮command1,应该怎么写代码?
#6
还有,如果不是文本文件,比如说是doc文件怎么办?
#7
//如果我用一个替换按钮command1,应该怎么写代码
把我的代码粘过去就行,设置好路径,和欲被替换的字串
//如果不是文本文件,比如说是doc文件怎么办
只能通过byte数组进行查找、替换
如果是doc文件还好一些,可以用word对象
把我的代码粘过去就行,设置好路径,和欲被替换的字串
//如果不是文本文件,比如说是doc文件怎么办
只能通过byte数组进行查找、替换
如果是doc文件还好一些,可以用word对象
#8
如果是别的文件,有比如说是rpt文件呢?
#9
rainstormmaster(rainstormmaster) :我试过了,文件可以找到,但是没有被替换,代码如下:
Private Sub Command1_Click()
Dim buff() As Byte
Dim l As Long
Dim filename As String
filename = "f:\zy.txt"
l = FileLen(filename)
ReDim buff(l - 1)
Open filename For Binary As #1
Get #1, , buff
Close #1
Dim s As String
s = StrConv(buff, vbUnicode)
Replace s, "zydb.mdb", Text1.Text
Kill filename
Open filename For Binary As #1
Put #1, , s
Close #1
End Sub
问题在哪里呢?多多感谢!!!
Private Sub Command1_Click()
Dim buff() As Byte
Dim l As Long
Dim filename As String
filename = "f:\zy.txt"
l = FileLen(filename)
ReDim buff(l - 1)
Open filename For Binary As #1
Get #1, , buff
Close #1
Dim s As String
s = StrConv(buff, vbUnicode)
Replace s, "zydb.mdb", Text1.Text
Kill filename
Open filename For Binary As #1
Put #1, , s
Close #1
End Sub
问题在哪里呢?多多感谢!!!
#10
Private Sub Command1_Click()
Dim buff() As Byte
Dim l As Long
Dim filename As String
filename = "f:\zy.txt"
l = FileLen(filename)
ReDim buff(l - 1)
Open filename For Binary As #1
Get #1, , buff
Close #1
Dim s As String
s = StrConv(buff, vbUnicode)
s=Replace( s, "zydb.mdb", Text1.Text)'我犯了一个低级错误,没指定返回值
Kill filename
Open filename For Binary As #1
Put #1, , s
Close #1
End Sub
Dim buff() As Byte
Dim l As Long
Dim filename As String
filename = "f:\zy.txt"
l = FileLen(filename)
ReDim buff(l - 1)
Open filename For Binary As #1
Get #1, , buff
Close #1
Dim s As String
s = StrConv(buff, vbUnicode)
s=Replace( s, "zydb.mdb", Text1.Text)'我犯了一个低级错误,没指定返回值
Kill filename
Open filename For Binary As #1
Put #1, , s
Close #1
End Sub
#11
谢谢rainstormmaster(rainstormmaster) ,没有问题!
可是如果文本使用的是全角字符,就不能替换了,为什么呢?
可是如果文本使用的是全角字符,就不能替换了,为什么呢?
#12
谢谢rainstormmaster(rainstormmaster) ,请问为什么chm文件中的字符替换之后再还原,这个文件就损坏了?
#13
请问为什么chm文件中的字符替换之后再还原,这个文件就损坏了?
这是因为:
s = StrConv(buff, vbUnicode)
这条语句将非文本的字符都过滤了
这是因为:
s = StrConv(buff, vbUnicode)
这条语句将非文本的字符都过滤了
#14
怎样才能不改变文件结构呢?
#15
//怎样才能不改变文件结构呢?
没别的办法,只能根据文件格式写
没别的办法,只能根据文件格式写
#16
谢谢,结帖
#1
Replace()
#2
2进制转换为字符串:
dim b() as byte '放2进制的数据
dim v as variant
dim s as string
v=b
s=v
首先将数据转为字符串,然后在用instr、mid等函数慢慢转。
比如:
dim p as long
p=instr(....)
mid$(s,p,3)="ABC" '注意,mid函数可以这么用,当然用replace也可以。
dim b() as byte '放2进制的数据
dim v as variant
dim s as string
v=b
s=v
首先将数据转为字符串,然后在用instr、mid等函数慢慢转。
比如:
dim p as long
p=instr(....)
mid$(s,p,3)="ABC" '注意,mid函数可以这么用,当然用replace也可以。
#3
AresChen(AresChen) :你可能没看清楚,我的问题是必须使用二进制存取模式,用TextBox1中的字符串批量替换e:\abc.bat文件中的某些相同的字符串,不是转换制式,是替换字符串.
#4
如果文件是文本文件的话:
dim buff() as byte
dim l as long
dim filename as string
filename="你的文件路径"
l=filelen(filename)
redim buff(l-1)
open filename for binary as #1
get #1,,buff
close #1
dim s as string
s=strconv(buff,vbunicode)
Replace s, "要替换的内容", text1.Text
kill filename
open filename for binary as #1
put #1,,s
close #1
dim buff() as byte
dim l as long
dim filename as string
filename="你的文件路径"
l=filelen(filename)
redim buff(l-1)
open filename for binary as #1
get #1,,buff
close #1
dim s as string
s=strconv(buff,vbunicode)
Replace s, "要替换的内容", text1.Text
kill filename
open filename for binary as #1
put #1,,s
close #1
#5
rainstormmaster(rainstormmaster) :如果我用一个替换按钮command1,应该怎么写代码?
#6
还有,如果不是文本文件,比如说是doc文件怎么办?
#7
//如果我用一个替换按钮command1,应该怎么写代码
把我的代码粘过去就行,设置好路径,和欲被替换的字串
//如果不是文本文件,比如说是doc文件怎么办
只能通过byte数组进行查找、替换
如果是doc文件还好一些,可以用word对象
把我的代码粘过去就行,设置好路径,和欲被替换的字串
//如果不是文本文件,比如说是doc文件怎么办
只能通过byte数组进行查找、替换
如果是doc文件还好一些,可以用word对象
#8
如果是别的文件,有比如说是rpt文件呢?
#9
rainstormmaster(rainstormmaster) :我试过了,文件可以找到,但是没有被替换,代码如下:
Private Sub Command1_Click()
Dim buff() As Byte
Dim l As Long
Dim filename As String
filename = "f:\zy.txt"
l = FileLen(filename)
ReDim buff(l - 1)
Open filename For Binary As #1
Get #1, , buff
Close #1
Dim s As String
s = StrConv(buff, vbUnicode)
Replace s, "zydb.mdb", Text1.Text
Kill filename
Open filename For Binary As #1
Put #1, , s
Close #1
End Sub
问题在哪里呢?多多感谢!!!
Private Sub Command1_Click()
Dim buff() As Byte
Dim l As Long
Dim filename As String
filename = "f:\zy.txt"
l = FileLen(filename)
ReDim buff(l - 1)
Open filename For Binary As #1
Get #1, , buff
Close #1
Dim s As String
s = StrConv(buff, vbUnicode)
Replace s, "zydb.mdb", Text1.Text
Kill filename
Open filename For Binary As #1
Put #1, , s
Close #1
End Sub
问题在哪里呢?多多感谢!!!
#10
Private Sub Command1_Click()
Dim buff() As Byte
Dim l As Long
Dim filename As String
filename = "f:\zy.txt"
l = FileLen(filename)
ReDim buff(l - 1)
Open filename For Binary As #1
Get #1, , buff
Close #1
Dim s As String
s = StrConv(buff, vbUnicode)
s=Replace( s, "zydb.mdb", Text1.Text)'我犯了一个低级错误,没指定返回值
Kill filename
Open filename For Binary As #1
Put #1, , s
Close #1
End Sub
Dim buff() As Byte
Dim l As Long
Dim filename As String
filename = "f:\zy.txt"
l = FileLen(filename)
ReDim buff(l - 1)
Open filename For Binary As #1
Get #1, , buff
Close #1
Dim s As String
s = StrConv(buff, vbUnicode)
s=Replace( s, "zydb.mdb", Text1.Text)'我犯了一个低级错误,没指定返回值
Kill filename
Open filename For Binary As #1
Put #1, , s
Close #1
End Sub
#11
谢谢rainstormmaster(rainstormmaster) ,没有问题!
可是如果文本使用的是全角字符,就不能替换了,为什么呢?
可是如果文本使用的是全角字符,就不能替换了,为什么呢?
#12
谢谢rainstormmaster(rainstormmaster) ,请问为什么chm文件中的字符替换之后再还原,这个文件就损坏了?
#13
请问为什么chm文件中的字符替换之后再还原,这个文件就损坏了?
这是因为:
s = StrConv(buff, vbUnicode)
这条语句将非文本的字符都过滤了
这是因为:
s = StrConv(buff, vbUnicode)
这条语句将非文本的字符都过滤了
#14
怎样才能不改变文件结构呢?
#15
//怎样才能不改变文件结构呢?
没别的办法,只能根据文件格式写
没别的办法,只能根据文件格式写
#16
谢谢,结帖