Link to home
Start Free TrialLog in
Avatar of hwassinger
hwassingerFlag for United States of America

asked on

parsing data in a function

I have a field ptage that contains the patients age formatted as XXXY
where XXX can be 1,2 or 3 digits and Y will be either D,M,Y

How can I parse out the XXX and the Y into separate fields?

e.g.
           Num     Alpha  
21D =  21         D
3M       3           M
101Y   101       y
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

post sample values

Avatar of HndlWCare
HndlWCare

This should help:

Dim strField As String
strField = "123D"
 
If (Len(strField) > 0) Then
    MsgBox Right(strField, 1)
    MsgBox Left(strField, (Len(strField) - 1))
End If
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Have you read matthewspatrick's article on regular expressions? For the requirement you describe above, I would expect a pattern like:

^(\d{1,3})([yYmMdD])$

Open in new window


With that, your number would be in group 1 and your letter code would be in group 2.