www.webdeveloper.com
Results 1 to 5 of 5

Thread: parse int from aplha numeric string

  1. #1
    Join Date
    Nov 2003
    Location
    California
    Posts
    248

    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.

    Thanks in advance.

  2. #2
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    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. #3
    Join Date
    Nov 2003
    Location
    California
    Posts
    248
    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

  4. #4
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    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 04:45 PM.

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles