Results 1 to 6 of 6

Thread: remove spaces from the front and back?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    remove spaces from the front and back?

    how do i remove the spaces from this string: " Hello World "

    i want to change that string to "Hello World"

    so i just want to remove the space from the front and back, anyone know an easy way to do this?

  2. #2
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: remove spaces from the front and back?

    use the Trim() function
    VB Code:
    1. yourstring = Trim$(yourstring)

    casey.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: remove spaces from the front and back?

    If you need you can also use the LTrim$() and RTrim$() functions to remove whitespace from the left edge only and right edge only, respectively.

  4. #4
    Addicted Member JensPeder's Avatar
    Join Date
    Sep 2005
    Posts
    249

    Re: remove spaces from the front and back?

    Text1.text = Trim$(Text1.text) - Will this work on a multilined textbox? Or whats the best way of doing that?

    (not at home atm, so I can't test )

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: remove spaces from the front and back?

    It removes all whitespace from the left and right of a string.

    If you want to apply it to all lines,
    VB Code:
    1. Dim lines() As String, i As Long
    2. lines = Split(Text1.Text, vbNewLine)
    3. For i = 0 To UBound(lines)
    4.     lines(i) = Trim$(lines(i))
    5. Next i
    6. Text1.Text = Join(lines, vbNewLine)

  6. #6
    Addicted Member JensPeder's Avatar
    Join Date
    Sep 2005
    Posts
    249

    Re: remove spaces from the front and back?

    Ah, I made my own code, but its slow

    Thanks man, I'll test it later
    Last edited by JensPeder; Nov 6th, 2005 at 01:20 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width