查找和替换 [英] Find and Replace

查看:67
本文介绍了查找和替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我编写的一些代码,用于查找和替换.

有一个文本框,用于查找"tbxFind",一个文本框用于替换"tbxReplace".
当我执行代码时,它会查找所有出现的事件并将其全部替换.

我想做的是一次找到一个事件,然后一次替换一次.
================================================== ======================

Here''s some code I wrote to do a find and replace.

There''s a textbox for find "tbxFind", and one for replace "tbxReplace".
When I execute the code, it finds all of the occurrences and replaces them all.

What I''d like to be able to do is find each occurrence one at a time, and replace it one at a time.
=========================================================================

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
      tbxEditor.Text = Replace(tbxEditor.Text, tbxFind.Text, tbxReplace.Text)
      MsgBox(" ' " & tbxFind.Text & " ' " & " Has been replaced with:" & " ' " & tbxReplace.Text & " ' ")
   End Sub





感谢





Thanks

推荐答案

您可以使用删除和插入",如下所示:
You could use Remove and Insert, like so:
Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click

        Dim iplace As String = tbxEditor.Text.IndexOf(tbxFind.Text)
        tbxEditor.Text = tbxEditor.Text.Remove(iplace, Len(tbxFind.Text)).Insert(iplace, tbxReplace.Text)

End Sub


这样一来,替换就变成了按钮点击.


This way, replacement is one by one on buttonclick.


这篇关于查找和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆