Hi i was curios how to parse, int from a long string that could have numbers and characters. I have to parse out the address number from a street addreess, like
'blah blah 1123' get the 1123 out
or
'1123 blah blah'
or
'blah 1111 blah' how can i get the 1123 out of these possibilities, or at least the last 2 digits, 23,
this is needed to calculate postnet 11 digit barcode if anyone is curious why i need it.
Hi sorry for the late reply but i did it the looong way (spent half of my day just for researching i guess i should have done this the first place), and actually it worked much better than any parsing code that used before
this code finds first continous number and grabs last 2 digits from it
Code:
if not isdbnull(RO_address1)
for i = 0 to RO_address1.Length() - 1
if not RO_address1.lastIndexOfAny(charlist,i ,1) = -1 then
flag = true
if not i = 0 then
firstnumber = RO_address1(i - 1)
end if
secondnumber = RO_address1(i)
else if flag = true and isnumeric(firstnumber) and isnumeric(secondnumber)
exit for
end if
next
end if
if not isnumeric(firstnumber) or not isnumeric(secondnumber) then
if not isdbnull(RO_address2)
for i = 0 to RO_address2.Length() - 1
if not RO_address2.lastIndexOfAny(charlist,i ,1) = -1 then
flag = true
if not i = 0 then
firstnumber = RO_address2(i - 1)
end if
secondnumber = RO_address2(i)
else if flag = true and isnumeric(firstnumber) and isnumeric(secondnumber)
exit for
end if
next
end if
end if
if not isnumeric(firstnumber) or not isnumeric(secondnumber) then
if not isdbnull(RO_address3)
for i = 0 to RO_address3.Length() - 1
if not RO_address3.lastIndexOfAny(charlist,i ,1) = -1 then
flag = true
if not i = 0 then
firstnumber = RO_address3(i - 1)
end if
secondnumber = RO_address3(i)
else if flag = true and isnumeric(firstnumber) and isnumeric(secondnumber)
exit for
end if
next
end if
end if
'response.write (firstnumber & "<BR>")
'response.write (secondnumber & "<BR>")
if not isnumeric(firstnumber) or not isnumeric(secondnumber) then
Ro_Postnet = Ro_Postnet & (10 - Checksum mod 10)
else
Ro_Postnet = Ro_Postnet & firstnumber & secondnumber
Checksum = Checksum + int32.parse(firstnumber) + int32.parse(secondnumber)
Ro_Postnet = Ro_Postnet & (10 - Checksum mod 10)
end if
this doesnt have full definition and every thing but it calculates a checksum postnet code too
Well what I was going to say if if this thing had the numbers after so many characters you can shave the letters off, then loop then shave or something, instead of looping all over the place. But again, why can't you move your data with a query string?
Bookmarks