CodeItBetter Programming Another VB Programming Blog

How to remove Leading/Trailing Spaces from the String

Posted on January 5, 2009
1
2
3
4
5
6
'String Manipulation - How to remove Leading/Trailing Spaces from the String

MyString = "   MyText   "
String1 = Trim(MyString)   'To Remove leading and trailing spaces in MyString. will display "MyText".
String1 = LTrim(MyString)  'To Remove leading spaces in MyString. will display "MyText    ".
String1 = RTrim(MyString)  'To Remove trailing spaces in MyString. will display "   MyText".
Comments (3) Trackbacks (0)
  1. How do we add a blank space at the end of a text box? Also, how do we make a MsgBox display variables on separate lines..e.g.

    CODE

    gData = nB1 & nB2 & aB1 & aB2 & tB & eB
    MsgBox(gData)

    END CODE

    In this case, all of the gData variables will display in the message box. However, how do we get each one to display on individual line?

    • To add a blank space after the text box content, you can use like:

      MsgBox Text1.Text & space(1) & Text2.Text

      or

      MsgBox Text1.Text & " " & Text2.Text

      To display line breaking in msgbox use vbcrlf.

      For example

      Msgbox "This is " & vbcrlf & "test."

      it will be showed in two lines.

  2. Okay thank you I already figured it out but of course your help is helpful to me an others. Here is what I used:

    MsgBox “Something” & vbNewLine & “Something”

    Thanks, so now I know I can use either or.


Reply

( Cancel )

 

No trackbacks yet.