Left Trim / Right Trim

Vav

Registered User.
Local time
Today, 03:25
Joined
Aug 29, 2002
Messages
36
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
 
You could probably do this with a combonation of the LEN, INSTR, and MID functions.
 
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:
Code:
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
 

Users who are viewing this thread

Back
Top Bottom