[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-05-09
3
Medium Priority
?
293 Views
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.
0
Comment
Question by:FaheemAhmadGul
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1000 total points
ID: 35724513
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

0
 
LVL 1

Author Closing Comment

by:FaheemAhmadGul
ID: 35731986
Many thanks.
0
 
LVL 75

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month18 days, 4 hours left to enroll

829 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