View Full Version : Left Trim / Right Trim


Vav
09-29-2006, 12:17 PM
Hello,

Does anyone know of a way that I can get rid of characters off a product code so all I am left with is just the characters greater than zero?

Example...

AA0000000652618... I only want to be left with 652618.

Would it be best to use a left trim or to use a right trim function? Unfortunately there is no standard for the product numbers... meaning that some numbers are 15 characters in length (as is above) but others maybe shorter or longer...

Also where I would add in the Right or Left Trim piece of code?
Regards,

Peter Vav

KeithG
09-29-2006, 12:31 PM
You could probably do this with a combonation of the LEN, INSTR, and MID functions.

boblarson
10-01-2006, 12:25 AM
Trim only removes spaces, so it won't help you here.

I tried to come up with something and it appears to work for me:

Public Function StripDown(strProdCode As String) As String
Dim blnValidChar As Boolean
Dim intLength As Integer
Dim intCount As Integer
intLength = Len(strProdCode)
Dim varArray(1 To 50) As String

intCount = 1
Do Until intCount = intLength + 1
varArray(intCount) = Mid(strProdCode, intCount, 1)
intCount = intCount + 1
Loop

intCount = 1


Do While intCount <> Len(strProdCode) + 1
If IsNumeric(varArray(intCount)) Then
If varArray(intCount) = 0 Then
Else
blnValidChar = True
End If
End If
If blnValidChar Then
StripDown = StripDown + varArray(intCount)
End If
intCount = intCount + 1
Loop

End Function