Solved

remove trailing carriage return(s) VbCrLf

Posted on 2004-03-24
8
1,649 Views
Last Modified: 2008-02-20
sometimes (but not always) at the end of my multiline textbox there are carriage returns created... how can I remove trailing carriage returns?

something like:
MyString = Replace(MyString, vbCrLf, "  ")
and Rtrim (MyString, 1)
combined?
0
Comment
Question by:NO_CARRIER
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 15

Expert Comment

by:unknown_routine
ID: 10672843
you can use this
MyString =Left(MyString , Len(MyString ) - 2)
0
 
LVL 15

Expert Comment

by:unknown_routine
ID: 10672845
-2 is because vbcrlf is infact 2 characters
0
 
LVL 1

Author Comment

by:NO_CARRIER
ID: 10672862
... how would I be able to figure out if the last character is indeed a carriage return?... (so it will only remove it if it's there... and not cut into the actual string.)
0
 
LVL 4

Expert Comment

by:learning_t0_pr0gram
ID: 10672873
how about..

Right(MyString, 6) = Replace(Right(MyString, 6), vbcrlf, "")
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 4

Expert Comment

by:learning_t0_pr0gram
ID: 10672927
MyString = Replace(Right(Text1.Text, 6), vbCrLf, "")
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 6) & MyString


..try that
0
 
LVL 15

Accepted Solution

by:
unknown_routine earned 65 total points
ID: 10672981


if right (MyString ,  2)=vbcrlf then

 MyString =Left(MyString , Len(MyString ) - 2)

end if
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 10672997
Can you just do

MyString = Replace(MyString, vbCrLf, "")
0
 
LVL 1

Author Comment

by:NO_CARRIER
ID: 10673013
that will replace all the carriage returns in the text... this is in a multi-line textbox.
I only want to remove trailing carriage returns at the END of the string.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
vba find the last empty column 10 81
VBA error replacing data 6 35
Run code from text file in vb 1 34
Hide vba in gp 7 49
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now