1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to Validate character pattern in string

Discussion in 'C++' started by nhicks, Jun 26, 2010.

  1. nhicks

    nhicks New Member

    Jun 26, 2010
    Likes Received:
    Trophy Points:
    Hi, I have this in VBA. Don't know much about C++, if this can be done with C++, help would be appreciated. thank you...nelson
    Function ValidAddr(addr As String) As Boolean
        Dim BadAddrs(2)
        Dim pos As Long
        Dim i As Integer
        pos = 0
        i = 0
        BadAddrs(0) = "PO BOX"
        BadAddrs(1) = "P.O BOX"
        BadAddrs(2) = " P.O. BOX"
        For i = LBound(BadAddrs) To UBound(BadAddrs)
            If (pos = 0) Then
                pos = InStr(1, addr, BadAddrs(i))
            End If
        Next i
        If (pos <> 0) Then
            ValidAddr = False
            ValidAddr = True
        End If
    End Function
    Sub CheckAddr()
        Dim isAddrPOBox As Boolean
        isAddrPOBox = False
        isAddrPOBox = ValidAddr("P.O BOX Rt. 11 P.O there")
        MsgBox isAddrPOBox
    End Sub

Share This Page