• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

Visual Basic Remove All Spaces from a String

Status
Not open for further replies.

Kaway

Banned
User
Joined
Aug 7, 2014
Messages
720
Reputation
0
Reaction score
5,766
Points
243
Credits
0
‎10 Years of Service‎
15%
Please note, if you want to make a deal with this user, that it is blocked.
[HIDE-THANKS]

Code:
> Public Function RemoveAllSpaces(ByVal InputString As String) _ 
As String

'NOTE: Intended for VB5 and below; if you have VB6, use built-in
'Replace Function. (e.g., MyString = Replace(MyString, " ", "")

Dim sAns As String
Dim lLen As String
Dim lCtr As Long, lCtr2 As Long
Dim sChar As String


lLen = Len(InputString)
sAns = InputString
lCtr2 = 1

For lCtr = 1 To lLen
   sChar = Mid(InputString, lCtr, 1)
   If sChar <> " " Then
       Mid(sAns, lCtr2, 1) = sChar
       lCtr2 = lCtr2 + 1
   End If
Next

If lCtr2 > 1 Then
   sAns = Left(sAns, lCtr2 - 1)
Else
   sAns = ""
End If

RemoveAllSpaces = sAns
End Function
[/HIDE-THANKS]

 
Status
Not open for further replies.
Back
Top