Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

how can I replace text in richtextbox?

Posted on 2004-03-29
5
432 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

837 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