songyangk(小草) 说的对。 dim a as string dim i as integer dim searchchar as string a="123456" searchchar="34" i=instr(1,a,searchchar, vbTextCompare) replace a,sezrchchar,"43" '''把34替换为43
其实很简单,用Replace函数就可以了。 dim a as string a=Replace("I love you","you","VB")
呵呵,还得考虑一下向上和向下呢! 我这有段源码,是我很早以前做的一个编辑器的查找模块, 至于替换,查找都可以了,替换也就不成问题了,记得给分喔,呵呵~~:'option1为向上,option2为向下查找 Public Sub FindText(ByVal start_at As Integer) Dim target As String If myfind.Option1 Then pos = bwl.rtb.SelStart bwl.rtb.SelStart = 0 bwl.rtb.SelLength = pos ok = StrReverse(bwl.rtb.SelText) bwl.rtb.SelStart = pos End If If myfind.Option2 Then If mynext = 1 And ss = myfind.Text1.Text Then pos = bwl.rtb.SelStart + lens mynext = 0 Else pos = bwl.rtb.SelStart End If bwl.rtb.SelStart = pos bwl.rtb.SelLength = Len(bwl.rtb.Text) - pos ok = bwl.rtb.SelText bwl.rtb.SelStart = pos End If target = myfind.Text1.Text If Option1 Then target = StrReverse(target) mypos = InStr(start_at, ok, target) If mypos > 0 Then If Option1 Then Targetpos = pos - mypos + 1 bwl.rtb.SelStart = Targetpos - Len(target) bwl.rtb.SelLength = Len(target) bwl.rtb.SetFocus lens = Len(target) End If If Option2 Then ss = target Targetpos = pos + mypos mynext = 1 bwl.rtb.SelStart = Targetpos - 1 bwl.rtb.SelLength = Len(target) bwl.rtb.SetFocus lens = Len(target) End If Else MsgBox "没找到!",,"飞龙备忘录" End If End Sub
替换可以用Replace函数。
dim a as string
dim i as integer
dim searchchar as string
a="123456"
searchchar="34"
i=instr(1,a,searchchar, vbTextCompare)
replace a,sezrchchar,"43" '''把34替换为43
dim a as string
a=Replace("I love you","you","VB")
我这有段源码,是我很早以前做的一个编辑器的查找模块,
至于替换,查找都可以了,替换也就不成问题了,记得给分喔,呵呵~~:'option1为向上,option2为向下查找
Public Sub FindText(ByVal start_at As Integer)
Dim target As String
If myfind.Option1 Then
pos = bwl.rtb.SelStart
bwl.rtb.SelStart = 0
bwl.rtb.SelLength = pos
ok = StrReverse(bwl.rtb.SelText)
bwl.rtb.SelStart = pos
End If
If myfind.Option2 Then
If mynext = 1 And ss = myfind.Text1.Text Then
pos = bwl.rtb.SelStart + lens
mynext = 0
Else
pos = bwl.rtb.SelStart
End If
bwl.rtb.SelStart = pos
bwl.rtb.SelLength = Len(bwl.rtb.Text) - pos
ok = bwl.rtb.SelText
bwl.rtb.SelStart = pos
End If
target = myfind.Text1.Text
If Option1 Then target = StrReverse(target)
mypos = InStr(start_at, ok, target)
If mypos > 0 Then
If Option1 Then
Targetpos = pos - mypos + 1
bwl.rtb.SelStart = Targetpos - Len(target)
bwl.rtb.SelLength = Len(target)
bwl.rtb.SetFocus
lens = Len(target)
End If
If Option2 Then
ss = target
Targetpos = pos + mypos
mynext = 1
bwl.rtb.SelStart = Targetpos - 1
bwl.rtb.SelLength = Len(target)
bwl.rtb.SetFocus
lens = Len(target)
End If
Else
MsgBox "没找到!",,"飞龙备忘录"
End If
End Sub
发个form给你!email?
[email protected]谢谢了!!!
呵呵,咱是个初学者,以后还会有很多问题请教大家,到时候你可要帮忙哦(一定给分)~~
没有收到邮件
????