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".

Related posts:

  1. How to strip out leading and trailing characters (Extended Trim)
  2. How to remove all spaces from string
  3. How to remove Duplicate Spaces from a string
  4. How to Strip out extra tabs, CrLf and multiple spaces
  5. How To Capitalize The First Character Of Each Word In A String/Phrase.
  6. How to remove Duplicate characters from a string
  7. How to count the number of spaces in a string
  8. How to Trim all Non-printing Characters from a given String
  9. How to find the first number in a string
  10. How to find the first number with thousand separator in a string

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.


Leave a comment


No trackbacks yet.