• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

remove trailing spaces from text file vb

Hi Experts
I have code that takes text intered into a multiline text box, converts it into an image and inserts into a richtextbox. Everything works fine until i press enter at the last line. This creates a blank space at the bottom of the image. How can i remove this space?
I have tried RTrim and Trim to no avail.
0
isnoend2001
Asked:
isnoend2001
1 Solution
 
DhaestCommented:
The easiest way:
left(text1.Text,len(text1.Text)-2)
(a vbcrlf (= enterkey) will add 2 places, but these are not seen as spaces but a special char)
0
 
isnoend2001Author Commented:
thanks Dhaest
That works, that was fast easy
Your the man
0
 
Shiju SasidharanCommented:
hi
try this
'==========================================
Private Sub Command3_Click()
    'Usage
     Dim s
     s = vbCrLf & "This is Test Data" & vbCrLf & vbCrLf
     MsgBox RemoveRightLeftNewLines(s)
End Sub

Public Function RemoveRightLeftNewLines(ByVal StringToTrim As String) As String
On Error GoTo Last:
    StringToTrim = Trim(StringToTrim)
    While (Left(StringToTrim, 1) = vbCr Or Left(StringToTrim, 1) = vbLf) And Len(StringToTrim) > 0
        StringToTrim = Trim(Right(StringToTrim, Len(StringToTrim) - 1))
        DoEvents
    Wend
    While (Right(StringToTrim, 1) = vbCr Or Right(StringToTrim, 1) = vbLf) And Len(StringToTrim) > 0
        StringToTrim = Trim(Left(StringToTrim, Len(StringToTrim) - 1))
        DoEvents
    Wend
    RemoveRightLeftNewLines = StringToTrim
    Exit Function
Last:
    MsgBox Err.Description
    Err.Clear
End Function
'===============================
;-)
Shiju
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now