Solved

how can I replace text in richtextbox?

Posted on 2004-03-29
5
433 Views
Last Modified: 2008-02-01
Hi, all
How can I replace TEXT in RichTEXT box??
I can not find to method in Richtexbox to replace TEXT?
Can anyone provide some coding?
0
Comment
Question by:davidlam8888
5 Comments
 
LVL 48

Accepted Solution

by:
Mikal613 earned 500 total points
ID: 10708510
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 10708522
VB.net has introduced a number of changes to the way you access the RichTextBox's properties. SelUnderline, SelBold, SelStrikethrough etc are now available in the

richTextBox1.SelectionFont

property. For example, in VB.net, use

richTextBox1.SelectionFont.Underline

instead of

richTextBox1.SelUnderline

0
 
LVL 6

Expert Comment

by:KarunSK
ID: 10708580
Use this:

        Dim strFind As String = "stringtofind"
        Dim iPos As Integer = RichTextBox1.Find(strFind)
        RichTextBox1.Select(iPos, strFind.Length)
        RichTextBox1.SelectedText = "stringtoreplace"

Karun.
0
 
LVL 35

Expert Comment

by:YZlat
ID: 10710428
0
 
LVL 19

Expert Comment

by:Desp
ID: 10711685
try this:

assuming the string you want to search in richtextbox1 is written in textBox1 and the button1 is the button which will tell you the index ...

set your richTextBox.HideSelection property to false( which is true by default)  so that this code can show you the occurences of the required text..


Dim position As Integer = 0 ' in the declaration section of your form class

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

       Dim index As Integer = RichTextBox1.Text.IndexOf(TextBox1.Text, position)' get the index of next occurance

       If (index > -1) Then' if the word is found
           RichTextBox1.Select(index, TextBox1.Text.Length) ' select and show the found text in the richtextbox

' You can also remove the line below to have the "FIND" Feature only instead of "FIND and REPLACE" feature
          RichTextBox1.SelectedText = "New Word" 'put your word(s) that you want tyo replace

           position = index + TextBox1.Text.Length        'update the position        

        Else
           MessageBox.Show("The string " & TextBox1.Text & " cannot be found")
        End If


   End Sub
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question