关于查找的问题

ouywj 2003-10-10 10:40:11
我新做了一个记事本程序,只是可惜没有添加查找功能,有谁能告诉我怎样在记事本程序中添加查找功能,并且显示出查找字符的个数。我以高分相送。
...全文
37 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lamshy 2003-10-10
  • 打赏
  • 举报
回复
这是MSDN的例子,看看能不能帮上忙吧!
Public Function FindMyText(ByVal searchText As String, ByVal searchStart As Integer, ByVal searchEnd As Integer) As Integer
' Initialize the return value to false by default.
Dim returnValue As Integer = -1

' Ensure that a search string and a valid starting point are specified.
If searchText.Length > 0 And searchStart >= 0 Then
' Ensure that a valid ending value is provided.
If searchEnd > searchStart Or searchEnd = -1 Then
' Obtain the location of the search string in richTextBox1.
Dim indexToText As Integer = richTextBox1.Find(searchText, searchStart, searchEnd, RichTextBoxFinds.MatchCase)
' Determine whether the text was found in richTextBox1.
If indexToText >= 0 Then
' Return the index to the specified search text.
returnValue = indexToText
End If
End If
End If
ouywj 2003-10-10
  • 打赏
  • 举报
回复
To cuizm(射天狼):
我用的是RICHTEXTBOX,请问查找函数到哪里去找?
IsMe 2003-10-10
  • 打赏
  • 举报
回复
private sub findTxt(byval cTxt as string,optional byval lStart as long=-1,optional byval bFromBegin as boolean=true,optional byval bIgnoorUL as boolean = true)
dim I as long
dim J as integer

J=abs(cint(bIgnoorUL)
if bFromBegin then
if lStart=-1 then lStart=1
i=instr(lStart,text1.text,ctxt,J)
else

i=instrrev(text1.text,ctxt,lStart,J)
end if

if i<1 then
msgbox "找不到"
else
text1.selstart=I
text1.sellength=len(ctxt)
end if
end sub
没有调试,意思应该是这样的
射天狼 2003-10-10
  • 打赏
  • 举报
回复
你是用什么控件做的记事伯,如果是TEXT控件,则需要自己写函数了,如果是RICHTEXTBOX,则提供了查找函数,不过查找字符的个数还得自己算!!
Mars.CN 2003-10-10
  • 打赏
  • 举报
回复
你在自动生成DIM窗体中看看(生成一个DIM窗体),这里面有查找和替换的选项,在里面参考一下。
海牛 2003-10-10
  • 打赏
  • 举报
回复
用Instr函数吧
从字符串"AAAABBAAA"的第一个字符开始查找字符"BB"
lPos=Instr(1,"AAAABBAAABBAA","BB")
返回lPos=5
再调用一次
lPos=Instr(lPos+1,"AAAABBAAABBAA","BB")
返回lPos=10

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧