473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

RichtextBox trim problem

Hello,

In my code I use the following command:

me.richtextbox1.text = me.richtextbox1.text.trim

By doing this I lose al my text formatting, it seems that by setting the text property of a richtextbox you lose al the formatting.
Any idea how I can remove the leading and trailing spaces in a text without losing the rtf formatting?

Thanks in advance.

David
Aug 2 '07 #1
2 4100
Already found a way to resolve this:

Public Shared Sub TrimRichTextBox(ByRef RichTextControl As RichTextBox, _
Optional ByVal LeadingSpaces As Boolean = True, _
Optional ByVal TrailingSpaces As Boolean = True)
Try
If LeadingSpaces Then
Do While RichTextControl.Text.StartsWith(" ")
RichTextControl.SelectionStart = 0
RichTextControl.SelectionLength = 1
RichTextControl.SelectedText = ""
Loop
End If
If TrailingSpaces Then
Do While RichTextControl.Text.EndsWith(" ")
RichTextControl.SelectionStart = RichTextControl.Text.Length - 1
RichTextControl.SelectionLength = 1
RichTextControl.SelectedText = ""
Loop
End If
Catch ex As Exception
Throw New Exception(System.Reflection.MethodInfo.GetCurrentM ethod.Name, ex)
End Try
End Sub

Hello,

In my code I use the following command:

me.richtextbox1.text = me.richtextbox1.text.trim

By doing this I lose al my text formatting, it seems that by setting the text property of a richtextbox you lose al the formatting.
Any idea how I can remove the leading and trailing spaces in a text without losing the rtf formatting?

Thanks in advance.

David
Aug 2 '07 #2
kenobewan
4,871 Expert 4TB
Well done, I assume that lefttrim & righttrim would have worked also...
Aug 2 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: John Broderick | last post by:
I've got a problem with the RichTextBox control in .Net where the garbage collector doesn't reclaim its memory after I've finished with it. My program adds a series of rtb's to the control array...
0
by: nouno | last post by:
I am trying to spell check a richtextbox. Through code (shown below) I save the contents of the richtextbox to a rtf file, open the rtf file in Word, spell check it, save it, and then load the ftf...
1
by: Eric | last post by:
Using the 1.1 framework. We are using a newly created instance of a RichTextBox Class in our server code to manipulate RTF that is stored in the database. To clarify, we are not using or...
0
by: Vincent | last post by:
Dear all, I have implemented a class to export the content of RichTextBox to image in WYSISYG mode so that line breaks on the screen are the same as exported. C# Code: public struct...
3
by: Paul | last post by:
Hi, My RichTextBox has multiple lines of text. Most of the lines unfortunately end with a space. Is it possible to replace the space and NewLine/Line Feed with just the NewLine/LineFeed? So...
3
by: Fab | last post by:
Hi, How can I save the text edited in a richTextBox into a field of an Access table. I have an error using the following code: OleDbCommand toto = new OleDbCommand("UPDATE Table1 SET Field1 =...
8
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have created a Control that extends RichTextBox to do syntax-hilighting. My strategy is to have a timer that restarts every time a user types a key so that it can wait until the user pauses for...
0
by: Vimalathithan | last post by:
I just developing a editor. I have provide the options like Bold, Italic, underlin, font change, font size change. These font options are keep in with one toolstripbutton. the toolstripbar keep...
4
by: eBob.com | last post by:
I have a RichTextBox in which I'd like blanks to appear different from nothing. Imagine a file which does not fill up the RTB. You can't tell how many, if any, blanks might follow the last...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.