473,606 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5815
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.Te xtLength
' Check the ascii values of the current character
' Note, an ascii value of 10 indicates enter
If Asc(Mid(RichTex tBox1.Text, i, 1)) = 10 Then
' trim the string to remove trailing spaces
str = Trim(str) & vbCrLf
Else
str += Mid(RichTextBox 1.Text, i, 1)
End If
Next i

RichTextBox1.Te xt = 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.C rLf})
For i As Integer = 0 To arr.Length - 1
arr(i) = arr(i).TrimEnd( " ")
Next
str = String.Join(Con trolChars.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(s tr, "(\s)+\r\n" , ControlChars.Cr Lf)

Dim str As String 'Your string
Dim arr() As String = str.Split(New Char()
{ControlChars.C rLf})
For i As Integer = 0 To arr.Length - 1
arr(i) = arr(i).TrimEnd( " ")
Next
str = String.Join(Con trolChars.CrLf, arr)
There might be a better way than this ...
>Hi,

My RichTextBox has multiple lines of text. Most of the lines
unfortunatel y 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
9029
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 Settings\\XX\\Desktop\\- Copy of TestingFolder -\\jjjj hihi.doc"); where there is 2 space between dash and "Copy of TestingFolder", but after going through Runtime.getRuntime().exec(arg), it chopes off one space and
5
9395
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
10685
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 fields: BuildName and RoadName. Both have the following properties: size 50, not indexed, not required, allowed zero length. Some records have BuildName, RoadName as null, some have content. No content is 50 chr long. When i run a Len(BuildName)...
3
4534
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 = System.Drawing.ContentAlignment.MiddleCenter label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter label1.Text = "IDLE"; //4 char strin label2.Text = "RUN ";//4 char string, //but trailing space ignored and it is centered as thoug...
4
1751
by: Aaron | last post by:
is there a way to remove all white spaces in the html output? ie. everything as one line.
1
123163
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
3000
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 the string to check character one by one. Support not using MFC.
4
22315
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 the string. I am using something like the following: var txt = textarea_element.value.replace(/\n*$/, ''); But this replaced only the last newline(by changing '' to 'K', and
0
8010
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7942
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8429
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8084
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8300
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5963
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5461
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3969
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1550
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.