opt = Replace(opt, left(opt, 2), "")
That line is replacing any instance of the 2 characters
at left of the opt string. Since 1012 appears later, it
erases the 01, contracting 1012 to 12 and thereby losing
the 10.
A better way to do it, which is also more efficient:
i2 = 1
For i = 1 to fileCount
char2 = Mid(opt, i2, 2)
result = (CINT(char2)) mod 2
If result = 0 Then
optEven = optEven & char2
Else
optOdd = optOdd & char2
End If
i2 = i2 + 2
Next
i2 is used to hold the position in the string for
the next read. That method of getting char2
also saves on string allocations, since it's not
recreating the opt string with each iteration.
Another thought: This won't matter if your string
is always guaranteed to have an even length,
but the \ operator returns an integer and is therefore
probably better to use. If you have a string with, say,
21 characters then \ will return a file count of 10
but / will return a file count of 10.5. So a script
using \ can complete, dropping the last character. But
a script using / will fail.
> Hi,
>
> I am including a part of a code below with the output I got. Inn this
> code I read in 2 chars at a time from the "opt" string and divide the
> string opt into odd and even numbers. It works great but for some
> reason (I don't understand why) it does not read the "10" in the char2
> string itself.
>
> The basic purpose is to divide the opt string into odd and even
> strings taking 2 chars at a time starting from the left. Pleeaze help
> me !!!!!
>
>
> Smaple Code:
> ===========
> optEven=""
> optOdd=""
> opt="02030501070911131506080410121416"
> if len(opt) > 0 then 'gives the len of the string to be parsed as it
> varies for diffent applications
> fileCount = (len(opt))/2 'fileCount holds info about the #
> of files to be created
> end if
>
> For i= 1 to fileCount
> '1 extract 2 numeric chars from the string until end of string
> char2=left(opt,2)
> opt=Replace(opt,left(opt,2),"")
> result = (CINT(char2)) mod 2
> if result = 0 then
> optEven=optEven & char2
> else
> optOdd=optOdd & char2
> end if
> next
>
>
> output
> ======
> opt=02030501070911131506080410121416
> char2=02
> char2=03
> char2=05
> char2=01
> char2=07
> char2=09
> char2=11
> char2=13
> char2=15
> char2=06
> char2=08
> char2=04
> char2=12
> char2=14
> char2=16
>
>