Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Spaces in String URGENT HELP Needed !

Status
Not open for further replies.

Chance1234

IS-IT--Management
Joined
Jul 25, 2001
Messages
7,871
Location
US
Its monday is all i can say im trying to strip out postal codes from fields in my Access DB, trouble is the postal codes are all different lengths

here is the code i have but its not working :-(

'----------- --------------------------------------------PO BOX Fields----------------
If ChkCnt <> 9 Then
If Left(StRflDs(ChkCnt), 2) = &quot;PO&quot; Then

PosChk = InStr(8, &quot; &quot;, StRflDs(ChkCnt), vbTextCompare)

StRflDs(9) = Left(StRflDs(ChkCnt), PosChk + 1)
StRflDs(ChkCnt) = Right(StRflDs(ChkCnt), Len(StRflDs(ChkCnt) - PosChk))
End If
End If

 
incode = left(postcode,instr(postcode, &quot; &quot;) - 1)
outcode = mid(postcode,instr(postcode, &quot; &quot;) + 1)

 
?Join(Split(&quot;Test Of String Rewriting&quot;), &quot;&quot;)
TestOfStringRewriting

Aivars
 
got my instr function the wrong way around in the end


 
problem sorted i got my instr function the wrong way around in the end


 
Yes, BUT you are probably making this more complicated than it shoulda/woulda/coulda be.

If YOU are discussing U.S. postal codes, they only come in two flavors. Five digit and Nine digit. Problem solved? Just loop through the &quot;postal code&quot; field regardless of length and extraneous 'stuffffffff'. The first five chars which are numeric are the basic postal code. If there are four more, they are the &quot;+Four&quot; part.
Assuming that [StRflDs] is the field for the postal code & 'Stufffffffffff':

Code:
Public Function basStripZip(Postal As String) As String

    'Usage/Example
    '? basStripZip(&quot;P.O. 21044-3091HaHaHa&quot;)
    '21044-3091



    Dim Idx As Integer                  'String Index/counter
    Dim MyZip As String                 'Holding place for the 5 Digit Zip
    Dim MyPlus4 As String               'Holding place for the +4 Zip
    Dim strTemp4 As String              'Conditional for the +4 part
    Dim strTemp5 As String              'Conditional for the Zip Code

    For Idx = 1 To Len(Postal)          'Walk the string for each Char
        MyChr = Mid(Postal, Idx, 1)     'Extract Char at Position
        If (IsNumeric(MyChr)) Then      'Check for numeric
            If (Len(MyZip) < 5) Then    'See if we are sitll in 5 digit zion
                MyZip = MyZip & MyChr   'Add to 5 digit
             Else
                MyPlus4 = MyPlus4 & MyChr   'Or the +4 part
            End If
        End If
    Next Idx

    If (Len(MyZip) = 5) Then                'Check for at LEAST the BASIC
        strTemp5 = MyZip                    'If &quot;O.K.&quot; then stuff for output/return
    End If
End Function
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top