extract every odd digit from a numeric string

90405

Registered User.
Local time
Today, 15:35
Joined
Jul 4, 2004
Messages
21
I have a problem in which I would like to extract every odd digit in the length of a numeric string and then return this as a combined result

Could a simple function be derived for Excel?

Below is given an example:

Original Odd digit Result
0 1 0
9 2
7 3 7
1 4
0 5 0
2 6
1 7 1
0 8
5 9 5
1 10
1 11 1
1 12
1 13 1
1 14
4 15 4
1 16
0 17 0
0 18
1 19 1
0 20
5 21 5
1 22
1 23 1
2 24
1 25 1
0 26
1 27 1
1 28
0 29 0
8 30
1 31 1
0 32
8 33 8
1 34
0 35 0
1 36


i.e. resulting combination

070151140151110180
 
This can be used in Access and Excel..

Code:
Public Function GetOdd(strBase As String) As String

    Dim intCounter As Integer
    Dim intChar As Integer

    For intCounter = 1 To Len(strBase)
        intChar = CInt(Mid(strBase, intCounter, 1))
        If intChar Mod 2 = 1 Then
            GetOdd = GetOdd & CStr(intChar)
        End If
    Next intCounter

End Function

Pass the string you want to it.

Also, when did 0, 4, and 8 become odd numbers? :confused:
 
Hey Mile I think he/she means every other, odd as in 1st 3rd 5th.

Brian
 

Users who are viewing this thread

Back
Top Bottom