Results 1 to 3 of 3

Thread: Replacing Characters With......?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Caanaaadaaaaaaa
    Posts
    7

    Post Replacing Characters With......?

    Hi,
    Would someone help me on this?
    I want to type an:
    "A" and printed as "A" on RichTextBox
    "B" and printed as "B" on RichTextBox where I have characters "AB".(This part is very easy for me!)
    But If I type:
    "B" and printed as "B" on RichTextBox
    "A" and printed as "A" on RichTextBox where I Should have characters "BA". But I do not want "BA" there. I want "BA" replaced by a character "C". (This part is very very hard for me!)
    I really appreciate any kind of feed back on this.
    Thanx
    nagu

    Ps: Please pay attention to sequences

  2. #2
    Matthew Gates
    Guest
    Try this:


    VB Code:
    1. Private RichTextBox1_Change()
    2.     With RichTextBox1
    3.          If InStr(1, .Text, "BA") Then .Text = Replace(.Text, "BA", "C")
    4.     End With
    5. End Sub

  3. #3
    Megatron
    Guest
    You don't need to search for the string. Replace() will do it automatically. This method will also preserve the SelStart position.
    VB Code:
    1. Private Sub RichTextBox1_Change()
    2.     lStart = RichTextBox1.SelStart
    3.     RichTextBox1.Text = Replace(RichTextBox1.Text, "BA", "C")
    4.     RichTextBox1.SelStart = lStart
    5. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width