-
Apr 15th, 2006, 10:57 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Remove trailing NewLines from string
I cant get my head around this, I have a string that may contain more than one newline at the end, and I want to trim them off, but I cant use String.Trim because the string my contain a space as the last char before the Newlines.
thanks in advance
-
Apr 15th, 2006, 11:24 AM
#2
Re: Remove trailing NewLines from string
Use the string functions to replace the chars you want. .Replace, .IndexOf, .LastIndexOf, and .SubString are what you want to look into using depending on your actual string contents.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 15th, 2006, 11:48 AM
#3
Re: Remove trailing NewLines from string
mystring = mystring.Substring(0, mystring.lastindexof(" "))
?
I don't live here any more.
-
Apr 15th, 2006, 12:05 PM
#4
Thread Starter
Frenzied Member
Re: Remove trailing NewLines from string
Originally Posted by wossname
mystring = mystring.Substring(0, mystring.lastindexof(" "))
?
no that doesnt work
VB Code:
Data = "abcdefghijkl" & vbNewLine & vbNewLine & vbNewLine
Data = Data.Substring(0, Data.LastIndexOf(" "))
MessageBox.Show(Data)
gives exception
Originally Posted by RobDog888
Use the string functions to replace the chars you want. .Replace, .IndexOf, .LastIndexOf, and .SubString are what you want to look into using depending on your actual string contents.
yes thats what ive been trying and I cant get it to work. Replace is not an option as there is other newlines within the string
-
Apr 15th, 2006, 12:06 PM
#5
Re: Remove trailing NewLines from string
give us an example string as we can not write the code without an example.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 15th, 2006, 12:16 PM
#6
Thread Starter
Frenzied Member
Re: Remove trailing NewLines from string
Originally Posted by RobDog888
give us an example string as we can not write the code without an example.
take a look at the post before yours
-
Apr 15th, 2006, 12:37 PM
#7
Re: Remove trailing NewLines from string
There is no space in your string?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 15th, 2006, 12:43 PM
#8
Thread Starter
Frenzied Member
Re: Remove trailing NewLines from string
yes your right, i dont need to use a space??? you mean newline? in my test string because i'm not interested in the replace function as that will remove all newlines, for arguments sake lets say the string looks like this then, but there could be more or less newlines at the end
Code:
"abc" & vbCrLf & "x zy " & vbcrlf & vbcrlf & "ab c de " & vbcrlf & vbcrlf & vbcrlf
-
Apr 15th, 2006, 01:04 PM
#9
Hyperactive Member
Re: Remove trailing NewLines from string
Why not simply loop through your string
While myString.(mystring.lenth -1) = Vbcrlf
'Remove Vbcrlf with Substring
Next
-
Apr 15th, 2006, 01:12 PM
#10
Thread Starter
Frenzied Member
Re: Remove trailing NewLines from string
ive tried this but it does nothing
VB Code:
While Data.Substring(Data.Length - 1, 1) = vbCrLf
Data = Data.Substring(Data.Length - 1)
End While
-
Apr 15th, 2006, 01:42 PM
#11
Re: Remove trailing NewLines from string
So you only want one newline and never have two or more of them together, correct?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 15th, 2006, 01:46 PM
#12
Thread Starter
Frenzied Member
Re: Remove trailing NewLines from string
Originally Posted by RobDog888
So you only want one newline and never have two or more of them together, correct?
no sorry I want to remove all new lines at the end of the string but leaving any spaces intact
-
Apr 15th, 2006, 02:09 PM
#13
Re: Remove trailing NewLines from string
Newlines are different then spaces. If you want to remove all newlines then Replace is what you want.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 15th, 2006, 02:11 PM
#14
Thread Starter
Frenzied Member
Re: Remove trailing NewLines from string
noooo not replace! for it is evil, it will take away all my newlines within the string
Code:
"abc" & vbCrLf & "x zy " & vbcrlf & vbcrlf & "ab c de " & vbcrlf & vbcrlf & vbcrlf
-
Apr 15th, 2006, 02:15 PM
#15
Re: Remove trailing NewLines from string
You can use Regex.Replace, although I still am not quite sure what you meant by your post just above. Also, Environment.Newline should be used instead of vbcrlf...
VB Code:
Dim MyLines As String = "this " & Environment.NewLine & Environment.NewLine & _
"and that" & Environment.NewLine & " and another!"
MessageBox.Show(System.Text.RegularExpressions.Regex.Replace(MyLines, Environment.NewLine, ""))
Last edited by gigemboy; Apr 15th, 2006 at 02:21 PM.
-
Apr 15th, 2006, 02:23 PM
#16
Re: Remove trailing NewLines from string
Ok, now that will need the use of SubString and LastIndexOf.
VB Code:
Dim str As String = "abc" & vbCrLf & "x zy " & vbCrLf & vbCrLf & "ab c de " & vbCrLf & vbCrLf & vbCrLf
Do While str.LastIndexOf(Environment.NewLine) = str.Length - 2
str = str.Substring(0, str.LastIndexOf(Environment.NewLine) - 2)
Loop
MessageBox.Show(str)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 15th, 2006, 02:38 PM
#17
Thread Starter
Frenzied Member
Re: Remove trailing NewLines from string
thx robdogg but that removes the final two chars of my string which are not newlines, it removes "e " from the end, where all other chars including spaces should remain intact
-
Apr 15th, 2006, 02:57 PM
#18
Re: Remove trailing NewLines from string
Try this...Should remove the last Newline, regardless of where it is positioned at...
VB Code:
Dim MyLines As String = "this " & Environment.NewLine & Environment.NewLine & _
"and that" & Environment.NewLine & " and another!"
MessageBox.Show(MyLines)
Dim MyBeginning As String = MyLines.Substring(0, MyLines.LastIndexOf(Environment.NewLine))
Dim MyEnd As String = MyLines.Substring(MyLines.LastIndexOf(Environment.NewLine) + 2, _
MyLines.Length - MyLines.LastIndexOf(Environment.NewLine) - 2)
MessageBox.Show(MyBeginning & MyEnd)
Of course, you could combine it all into one line, just wanted to make it a little more readable
Last edited by gigemboy; Apr 15th, 2006 at 04:03 PM.
-
Apr 16th, 2006, 06:18 AM
#19
Thread Starter
Frenzied Member
Re: Remove trailing NewLines from string
Originally Posted by gigemboy
Try this...Should remove the last Newline, regardless of where it is positioned at...
thx gigemboy but what I'm actually looking for is some code which will remove all trailing new lines from the string, but leaving any other char (including spaces) intact
-
Apr 16th, 2006, 06:34 AM
#20
Re: Remove trailing NewLines from string
This will remove all carriage return and line feed characters from the end of your string:
VB Code:
myString = myString.TrimEnd(Convert.ToChar(Keys.Return), Convert.ToChar(Keys.LineFeed))
-
Apr 16th, 2006, 06:36 AM
#21
Thread Starter
Frenzied Member
Re: Remove trailing NewLines from string
this is my example string
Code:
"abc" & Environment.NewLine & "x zy " & Environment.NewLine & Environment.NewLine & "ab c de " & Environment.NewLine & Environment.NewLine & Environment.NewLine
I just want to cut off the NewlInes at the end so it will be
Code:
"abc" & Environment.NewLine & "x zy " & Environment.NewLine & Environment.NewLine & "ab c de "
although this is only an example string, the string will be generated programatically so there could be only 1 newline at the end, or maybe 5 if you see what I mean
-
Apr 16th, 2006, 06:39 AM
#22
Re: Remove trailing NewLines from string
You can actually do it in a couple lines of code using regex if thats the case, since regex has a handly little "$" character that you can add to only match at the end of the string...
VB Code:
Dim MyLines As String = "this" & Environment.NewLine & _
"and that" & Environment.NewLine & "and another!" & _
Environment.NewLine & Environment.NewLine
'just shows you the string so you can compare with the result string
'to see if it looks the same
MessageBox.Show(MyLines)
Dim MyMatches As System.Text.RegularExpressions.MatchCollection = _
System.Text.RegularExpressions.Regex.Matches(MyLines, Environment.NewLine)
'just displays original count of newlines to see if it works
MessageBox.Show(MyMatches.Count.ToString)
MyLines = System.Text.RegularExpressions.Regex.Replace(MyLines, "(" & Environment.NewLine & ")*$", "")
'just results, shows count of newline character sequence in result
'as well as result string
Dim MyMatches2 As System.Text.RegularExpressions.MatchCollection = _
System.Text.RegularExpressions.Regex.Matches(MyLines, Environment.NewLine)
MessageBox.Show(MyMatches2.Count.ToString)
MessageBox.Show(MyLines & " ")
Last edited by gigemboy; Apr 16th, 2006 at 06:48 AM.
Reason: simpler regex pattern
-
Apr 16th, 2006, 06:40 AM
#23
Thread Starter
Frenzied Member
Re: Remove trailing NewLines from string
Originally Posted by jmcilhinney
This will remove all carriage return and line feed characters from the end of your string:
VB Code:
myString = myString.TrimEnd(Convert.ToChar(Keys.Return), Convert.ToChar(Keys.LineFeed))
this works perfectly, thanks a lot mate
ps I cant +++++rep you again yet so I will when I can
-
Apr 16th, 2006, 06:42 AM
#24
Re: [RESOLVED] Remove trailing NewLines from string
well a summary of my above post can be done in one line doing this:
VB Code:
Dim MyLines As String = "this" & Environment.NewLine & _
"and that" & Environment.NewLine & "and another!" & _
Environment.NewLine & Environment.NewLine
'removes trailing newlines
MyLines = System.Text.RegularExpressions.Regex.Replace(MyLines, "(" & Environment.NewLine & ")*$", "")
The rest was just results to make sure you could see to test.. But JM's post was fairly simple
Last edited by gigemboy; Apr 16th, 2006 at 06:49 AM.
Reason: Simpler regex pattern
-
Apr 16th, 2006, 06:44 AM
#25
Thread Starter
Frenzied Member
Re: [RESOLVED] Remove trailing NewLines from string
thx to gigemboy and robdog +rep when I can
-
Sep 19th, 2017, 01:46 PM
#26
New Member
Re: Remove trailing NewLines from string
I guess everyone want to do it in one line of vba... i like loops.
bSTR = Trim(bSTR)
While Right(bSTR, Len(bSTR)) = Asc(10) Or Right(bSTR, Len(bSTR)) = Asc(13)
bSTR = Left(bSTR, Len(bSTR) - 1)
Wend
-
Sep 19th, 2017, 01:59 PM
#27
New Member
Re: [RESOLVED] Remove trailing NewLines from string
Crud... rushing is never good. But this works:
While Asc(Right(bSTR, 1)) = 10 Or Asc(Right(bSTR, 1)) = 13
bSTR = Left(bSTR, Len(bSTR) - 1)
Debug.Print Len(bSTR)
Wend
-
Sep 19th, 2017, 06:44 PM
#28
Re: [RESOLVED] Remove trailing NewLines from string
Originally Posted by vb1der
Crud... rushing is never good. But this works:
While Asc(Right(bSTR, 1)) = 10 Or Asc(Right(bSTR, 1)) = 13
bSTR = Left(bSTR, Len(bSTR) - 1)
Debug.Print Len(bSTR)
Wend
This thread is 11.5 years old and it's in the VB.NET forum. Was posting some VBA code really all that useful?
-
Jul 10th, 2021, 12:19 AM
#29
New Member
Re: [RESOLVED] Remove trailing NewLines from string
Hello from 2021 !
jmcihinney, I have just created an account for the sole purpose of answering your question.
I am currently at work, half an hour after the end of my shift and I wanted a quick answer
on how to quickly trim any and all vbcrlf s at the end or beginning of my string
I have search google for "VBA trim trailing vbcrlf" and this forum thread is the second result.
The elegant answer you have given involving myString.TrimEnd, does not work because, yes, this is a vb.net answer.
Apparently no one asked this question before for VBA or maybe it is in the catacombs on the second page of google's search results.
So, I'm pretty happy that vb1der has posted a VBA answer.
And I will now test this answer
From VB immediate console
Code:
bSTR = "mystringblabla" & vbcrlf & vbcrlf & vbclf
print bSTR
mystringblabla
While Asc(Right(bSTR, 1)) = 10 Or Asc(Right(bSTR, 1)) = 13 : bSTR = Left(bSTR, Len(bSTR) - 1) : Wend
print bSTR
mystringblabla
marker------------------marker
And I made a function out of it too
Code:
Function TrimEnd(ByVal myString As String, myTrim As String) As String
If myString = "" Or myTrim = "" Then TrimEnd = myString: Exit Function
While Right(myString, Len(myTrim)) = myTrim: myString = Left(myString, Len(myString) - Len(myTrim)): Wend: TrimEnd = myString
End Function
-
Jul 10th, 2021, 03:20 AM
#30
Re: [RESOLVED] Remove trailing NewLines from string
Originally Posted by shodanx
Hello from 2021 !
jmcihinney, I have just created an account for the sole purpose of answering your question.
I am currently at work, half an hour after the end of my shift and I wanted a quick answer
on how to quickly trim any and all vbcrlf s at the end or beginning of my string
I have search google for "VBA trim trailing vbcrlf" and this forum thread is the second result.
The elegant answer you have given involving myString.TrimEnd, does not work because, yes, this is a vb.net answer.
Apparently no one asked this question before for VBA or maybe it is in the catacombs on the second page of google's search results.
So, I'm pretty happy that vb1der has posted a VBA answer.
And I will now test this answer
From VB immediate console
Code:
bSTR = "mystringblabla" & vbcrlf & vbcrlf & vbclf
print bSTR
mystringblabla
While Asc(Right(bSTR, 1)) = 10 Or Asc(Right(bSTR, 1)) = 13 : bSTR = Left(bSTR, Len(bSTR) - 1) : Wend
print bSTR
mystringblabla
marker------------------marker
And I made a function out of it too
Code:
Function TrimEnd(ByVal myString As String, myTrim As String) As String
If myString = "" Or myTrim = "" Then TrimEnd = myString: Exit Function
While Right(myString, Len(myTrim)) = myTrim: myString = Left(myString, Len(myString) - Len(myTrim)): Wend: TrimEnd = myString
End Function
Does the fact that someone not interested in VB.NET justify polluting the VB.NET forum with code that is of no use to anyone interested in VB.NET? No, it does not. We could pollute this forum with all sorts of other languages and even non-programming information and it might be useful to all sorts of people, but this is a VB.NET forum, so it's purpose is not to help those people. Maybe vb1der should have posted that code to a VBA site somewhere and then it would have been just as useful to you without crapping on this thread and this forum. I'm happy that you found an answer to your question but I don't want to have to wade through all sorts of garbage to get to the VB.NET stuff in this forum and I doubt anyone else does either.
-
Jul 10th, 2021, 03:29 AM
#31
New Member
Re: [RESOLVED] Remove trailing NewLines from string
I understand that however, this is the most one of the enticing google result for this query.
And it contains the correct answer for this question.
The problem is that there is no reliable way to change the google results to point toward the right answer in the right forum section.
The fact that this thread in particular has 17 thousand views is an indicator that a LOT of people are searching for this answer and hopefully are finding it here.
here is what the search result page looks from my end. I immediately knew I was on the right track when I saw it !
-
Jul 11th, 2021, 12:06 AM
#32
Re: [RESOLVED] Remove trailing NewLines from string
Originally Posted by shodanx
I understand that however
Let me finish that for you:
I don't care because it helped me so screw what this forum is actually for.
Have you made the effort to put this information in a logical place for other VBA developers? No, I didn't think so. I guess I'll join a knitting circle and post VBA answers on their message board because who cares what that board is actually for, right? This thread is a question about a VB.NET problem. That is its purpose. As such, an answer using VBA code is, by definition, not useful. The fact that it might be useful for some other purpose isn't relevant to that. Should we start posting Béarnaise sauce recipes here because someone might find that useful? I get that that post was useful for you and probably other VBA developers but that is completely irrelevant to my comment. This thread and this forum exist to help people with VB.NET problems so VBA code is NOT useful and should be posted somewhere that exists to help people with VBA problems. Maybe do that instead of wasting your time telling me that I should be OK with this VB.NET forum being polluted with irrelevant garbage by people who couldn't be bothered posting it in a sensible location because that might take a bit of extra effort on their part.
-
Jul 11th, 2021, 01:15 AM
#33
Re: [RESOLVED] Remove trailing NewLines from string
Originally Posted by shodanx
And I made a function out of it too
Code:
Function TrimEnd(ByVal myString As String, myTrim As String) As String
If myString = "" Or myTrim = "" Then TrimEnd = myString: Exit Function
While Right(myString, Len(myTrim)) = myTrim: myString = Left(myString, Len(myString) - Len(myTrim)): Wend: TrimEnd = myString
End Function
the Function might work, but ever heard of replace
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Jul 20th, 2021, 08:41 PM
#34
Re: Remove trailing NewLines from string
Originally Posted by jmcilhinney
This will remove all carriage return and line feed characters from the end of your string:
VB Code:
myString = myString.TrimEnd(Convert.ToChar(Keys.Return), Convert.ToChar(Keys.LineFeed))
Originally Posted by the182guy
this works perfectly, thanks a lot mate
ps I cant +++++rep you again yet so I will when I can
@jm… I know this is old but…
myString = myString.TrimEnd(vbCr, vbLf)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 20th, 2021, 10:20 PM
#35
Re: Remove trailing NewLines from string
Originally Posted by .paul.
@jm… I know this is old but…
myString = myString.TrimEnd(vbCr, vbLf)
Yeah, I wouldn't do it that way myself any more. I would tend to use this:
vb.net Code:
myString = myString.TrimEnd(ControlChars.Cr, ControlChars.Lf)
but it amounts to the same thing. It's the one thing I've learned in the last decade and a half.
-
Jul 22nd, 2021, 05:30 AM
#36
Re: [RESOLVED] Remove trailing NewLines from string
Just thought I'd throw in my two pennyworth... I'd've tried:
Code:
txt = txt.Replace(vbNewline & vbNewline, vbNewline)
Poppa
Along with the sunshine there has to be a little rain sometime.
-
Jul 22nd, 2021, 10:51 AM
#37
Re: [RESOLVED] Remove trailing NewLines from string
Originally Posted by Poppa Mintin
Just thought I'd throw in my two pennyworth... I'd've tried:
Code:
txt = txt.Replace(vbNewline & vbNewline, vbNewline)
Poppa
You wasted two pence there. That doesn't remove trailing newline characters
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 22nd, 2021, 02:44 PM
#38
Re: [RESOLVED] Remove trailing NewLines from string
Originally Posted by Poppa Mintin
Just thought I'd throw in my two pennyworth... I'd've tried:
Code:
txt = txt.Replace(vbNewline & vbNewline, vbNewline)
Poppa
this is what I used in some applications:
Code:
txt = txt.Replace(vbCr, "").Replace(vbLf, "")
but with the trim.end version, my future code will look more elegant
The best friend of any programmer is a search engine
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|