How to delete a full stop after the last sentence in a RichTextBox programmatically.

Posted on 2011-05-09
Last Modified: 2012-05-11
Please note I am using Visual Studio 2010.

I need help with code (in Visual Basic) that will search backwards for the first fullstop in a RichTextBox from the current cursor position and one finding it, will delete this full stop.
So if there is following text in a RichTextBox.

This is the first sentence.
This is the second sentence. This is the third target sentence.

And if the cursor is at the end of the above  paragraph (that is to the right of the fullstop after the third sentence,  I would like the code to search and find this last full stop in this paragraph and delete this full stop.
So the above paragraph after running the code will look like as follows:

This is the first sentence. This is the second sentence. This is the third target sentence

As you can see the full stop after the third sentence has been deleted after running the code.
Please note that before the code I am looking for runs, the cursor will be at the end of all the text in the RichTextBox.

Thank you for your help in anticipation.
Question by:FaheemAhmadGul
    LVL 74

    Accepted Solution

    How about this?
    Dim lastStop As Integer = Me.RichTextBox1.Rtf.LastIndexOf("."c)
    Me.RichTextBox1.Rtf = Me.RichTextBox1.Rtf.Substring(0, lastStop) & Me.RichTextBox1.Rtf.Substring(lastStop + 1)

    Open in new window


    Author Closing Comment

    Many thanks.
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    NP. Glad to help  = )

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now