473,386 Members | 1,796 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,386 software developers and data experts.

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
Sep 7 '06 #1
3 5787
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:
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
Sep 8 '06 #2
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

Sep 8 '06 #3
Or try this...

str = Regex.Replace(str, "(\s)+\r\n", ControlChars.CrLf)

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

Sep 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: aa | last post by:
Anybody know the solution to trailing space in argument of Runtime.getRuntime().exec(arg), Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler C:\\Documents and...
5
by: Donald Canton | last post by:
What's the best way to remove trailing whitespace from a string? For example: "John C. Doe \t" would become "John C. Doe". Thanks.
3
by: Andy B | last post by:
I've tried using Trim or RTrim to strip trailing space characters from my data. When I check on the transformed data space characters are still there. We have an address table containing two...
3
by: Mark Urish | last post by:
I want to center-align the text in 2 Label controls, and I want the 1st char of their text to line up ------------------------------------------------------------------------------ label1.TextAlign...
4
by: Aaron | last post by:
is there a way to remove all white spaces in the html output? ie. everything as one line.
1
by: Konstantinos Pachopoulos | last post by:
Hi, is there something corresponding to the java String.trim() method, ie trim start and trailing space/tab chars from string? say convert " asdf " to "asdf"? Thnx
6
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I think in built-in C/C++ functions, there is no direct function call to trim heading and trailing space characters, right? So, we have to implement it manually by iterating...
4
by: lihao0129 | last post by:
Hi, folks: I recently went through a strange problem with my Javascript code, say: I have a string variable which are from a 'textarea' element and I want to remove the trailing newlines inside...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.