Strip Spaces from String

Strip Spaces from String

Usually this function helps a lot in data cleansing.

Call the function FnCleanString with a string values and it will reformat and pass back a string with all the spaces removed.

You can modify this code to cater for other scenarios, say stripping numeric characters or stripping non alphabets from string.

Usefulness is very much on how creative you can apply this function. Have fun.
:)


Function FnCleanString(pString As String) As String
Dim tString As String
Dim tLength As Integer
Dim lCtr As Integer
   tString = ""
   tLength = Len(pString)
   For lCtr = 1 To tLength
       If Mid(pString, lCtr, 1) <> " " Then
          tString = tString & Mid(pString, lCtr, 1)
       End If
   Next lCtr
   FnCleanString = tString
End Function

You might also like...

Comments

Andrew Yap

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The greatest performance improvement of all is when a system goes from not-working to working.” - John Ousterhout