knrt.net
当前位置:首页 >> VB里记事本的查找功能查找下一个,与替换功能! >>

VB里记事本的查找功能查找下一个,与替换功能!

使用 replace() 函数.

dim m_start as integerprivate sub chazhao_click()dim l2 as integer l2 = len(text2) m_start = instr(m_start, text1, text2) if m_start 0 then text1.setfocus text1.selstart = m_start - 1 text1.sellength = l2 m_start = m_start + 1 else m_start = 1 end ifend subprivate sub form_load() m_start = 1end sub

假定所有控件都在一个窗体里,如果有其他问题lz自己调下~dim last as singleprivate sub command1_click() '查找for i = last to len(text1.text)if mid(text1.text, i, len(text2.text)) = text2.text then text1.setfocus text1.selstart = i - 1 text1.sellength = len(

新建一个模块,来定义查找的函数,里面代码如下:Option ExplicitPublic Function IsDelim(Char As String) As Boolean Select Case Asc(Char) Case 65 To 90, 95, 97 To 122 IsDelim = False Case Else: IsDelim = True End SelectEnd

在form1中,加入1个按钮,和1个文本框, 在form2中,加入两个按钮,和两个文本框, command1=查找下一个替换 command2=全部替换 form1.text1.text=需要替换的文本 form1.text1.text=被替换字串 form1.text1.text=替换字串 form2中的代码:

递归搜索字符串 替换

Private Sub command1_click() Dim sz As String sz = InputBox("输入要查找的字符串") For i = 1 To Len(Text1) If Mid(Text1, i, Len(sz)) = sz Then Print sz Text1.SelStart = i Text1.SelLength = Len(sz) Exit For End If Next i End Sub

Replace函数 描述返回一个字符串,该字符串中指定的子字符串已被替换成另一子字符串,并且替换发生的次数也是指定的.语法Replace(expression, find, replacewith[, start[, count[, compare]]])Replace函数语法有如下几部分:部分描述

Private Sub cmdExit_Click() End End Sub Private Sub cmdFind_Click() Dim StrCz As String, StrTh As String, I As Integer, J As Integer, K As Integer StrCz = InputBox("你要查找什么?", "查找", "上海市") StrTh = InputBox("你要将

用chr函数chr(10) & chr(13) 这就是回车换行符

网站首页 | 网站地图
All rights reserved Powered by www.knrt.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com