|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
String quickie: Remove trailing space from each RichTextBox line?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 in essence just removing the trailing space from each line? Thanks, Paul You might try the below code (not tested)
Dim str As String = "" Dim i As Integer ' Loop through the characters in the text box For i = 1 To RichTextBox1.TextLength ' Check the ascii values of the current character ' Note, an ascii value of 10 indicates enter If Asc(Mid(RichTextBox1.Text, i, 1)) = 10 Then ' trim the string to remove trailing spaces str = Trim(str) & vbCrLf Else str += Mid(RichTextBox1.Text, i, 1) End If Next i RichTextBox1.Text = str Thanks, Seth Paul wrote: Show quoteHide quote > 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 in essence just removing the trailing space from each line? > > > Thanks, > Paul Dim str As String 'Your string
Dim arr() As String = str.Split(New Char() {ControlChars.CrLf}) For i As Integer = 0 To arr.Length - 1 arr(i) = arr(i).TrimEnd(" ") Next str = String.Join(ControlChars.CrLf, arr) There might be a better way than this ... Show quoteHide quote > 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 in essence just removing the trailing space from each line? > Thanks, > Paul Or try this...
str = Regex.Replace(str, "(\s)+\r\n", ControlChars.CrLf) Show quoteHide quote > Dim str As String 'Your string > Dim arr() As String = str.Split(New Char() > {ControlChars.CrLf}) > For i As Integer = 0 To arr.Length - 1 > arr(i) = arr(i).TrimEnd(" ") > Next > str = String.Join(ControlChars.CrLf, arr) > There might be a better way than this ... > >> 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 in essence just removing the trailing space from each line? >> Thanks, >> Paul
Visual Basic beginner question
Search for files in folders? Date/Time Pickers/VB2005 app.config not copied to bin directory Opening a space delimited textfile in Excel using VB.net VB2005: Error Using a Separate Search Form How can I execute a simple command? how to open a form in C# Download tif from the web via a stream with progress indication Repeated Warning: "There are Updated Custom Wrappers Available..." |
|||||||||||||||||||||||