Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts

    get rid of extra spaces

    Hi,

    I've got data like that: var1, var2, var3..........

    I would like to transform it to this: var1,var2,var3. I've been trying to use the trim function but realized that it only removed the spaces at the beginning and at the end of the string... right? So I found in very usefull whammy's functions a function that does what I need but I don't know how to use it (since it's the first time I'm using one of these for something else than string manipulations). How to make them inheract?
    Code:
    Function RemoveExtraSpaces(ByVal str)
    	If IsNull(str) Then Exit Function
    	Dim resRegEx
    	Set resRegEx = New RegExp
    	resRegEx.Pattern = "\s+"
    	resRegEx.Global = True
    	RemoveExtraSpaces = resRegEx.Replace(str," ")
    End Function
    
    
    extraSpacesNotWanted=var1, var2, v   ar3, va r 4, etc.....
    thanx a lot for answers

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    RegEx are great, but this is faster.
    Code:
    dim original, vacumed
    
    original = "bla bla, bla ,bla"
    vacumed = replace(original," ","")

  • #3
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey frenchy!!!!!! thanx a lot 'hope you're doing alright with all your projects

  • #4
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    However, if someone feels like answering the question as it was asked in the first place, that would be good for me to see how that would have been done

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    newVar = RemoveExtraSpaces(extraSpacesNotWanted)

    (newVar could be the same var).
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #6
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    aaaaaaaaaaaaaaah! shame on me...... that was that easy... thanx a lot

    <edit>
    I don't know why I'm always trying funky and complicated things rather than checking what is the most simple and evident thing to do
    </edit>
    Last edited by jeskel; 11-14-2003 at 09:50 AM.


  •  

    Posting Permissions

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