# Thread: parse int from aplha numeric string

1. ## parse int from aplha numeric string

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.

2. Well is there a set number of characters for the letters and a set number for the numbers? Also, how come a query string will not work for this?

3. 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
end if
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
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
end if
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
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
end if
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

4. 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?
Last edited by PeOfEo; 12-14-2004 at 03:45 PM.

5. Registered User
Join Date
Jul 2004
Posts
300
int temp = int.Parse(string);