Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » removing all spaces from a string ???
Closed Thread
Old 06-15-2004, 01:02 PM   #1 (permalink)
 
True Techie

Join Date: Jan 2004

Posts: 164

petogaz

Default removing all spaces from a string ???

hi guys !!

i'm wondering how to remove spaces from a string in VBA (access).

for instance :

"i'm a newbe in VBA programming".

the result should be :

"i'manewbeinVBAprogramming".

any idea guyz ?

i know there's a function call Alltrim() but this removes only spaces from right and left not from the middle of string.

thanks in advance for your help !
__________________
\"you cant hold a good techie down\"
petogaz is offline  
Old 06-15-2004, 02:06 PM   #2 (permalink)
 
True Techie

Join Date: Jan 2004

Posts: 164

petogaz

Default

ok !!! guyz i found my way !


here's the code :

Code:
Public Function RemoveSpaces(strInput As String)
' Removes all spaces from a string of text
Test:
   If InStr(strInput, " ") = 0 Then
      RemoveSpaces = strInput
   Else
      strInput = Left(strInput, InStr(strInput, " ") - 1) _
      & Right(strInput, Len(strInput) - InStr(strInput, " "))
      GoTo Test
   End If
End Function

__________________
\"you cant hold a good techie down\"
petogaz is offline  
Old 06-15-2004, 07:15 PM   #3 (permalink)
 
Wizard Techie

Join Date: Apr 2004

Posts: 3,248

killians45

Default

just use mid. example is from something I had to write. But I was ignoring the " ' ", but instead of that name it spc = " ". So my code was like this:

Public Function serialNumdel(serialNum) As String

Dim x As Integer
Dim apo As String
Dim tempserialnum As String
apo = "'"

For x = 1 To Len(serialNum)
If Mid(serialNum, x, 1) = apo Then
tempserialnum = Mid(serialNum, 1, x - 1)
serialNum = tempserialnum & Mid(serialNum, x + 1, Len _
(serialNum) - 1)
x = x - 1
End If
Next

End Function


notice, serialnumber would be your text string, tempserialnumber would be just a temporary holder while we parsed through it and removed what was needed. Where you see this:

apo = "'"
change it to

spc = " "

of course, you'll need to change the declarations to

dim spc as string

instead of

dim apo as string
__________________
If you argue with an idiot he will drag you down to his level and beat you with experience.

I am not a fast writer.
I am not a slow writer.
I am a half-fast writer.

-Robert Asprin
killians45 is offline  
Old 06-16-2004, 03:27 AM   #4 (permalink)
 
True Techie

Join Date: Jan 2004

Posts: 164

petogaz

Default

thanks killians for your input. that also works fine .
thanks again.
__________________
\"you cant hold a good techie down\"
petogaz is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On