All pastes #437701 Raw Edit

benkillin

public text v1 · immutable
·published 2007-04-13 05:57 UTC
rendered paste body
public static String[] idScanToStringArray(String sText)
        {
            /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
             * idScanToStringArray(1): 
             *  Extracts various information from a string representing a Virginia ID barcode scan.
             * 
             * Author: Ben VanDenburg
             * Date: 04 April 2007
             * Copyright: 2007 Ben VanDenburg. ALL RIGHTS RESERVED EXCEPT THOSE EXPLICITLY GRANTED.
             *      You may use this code provided you insert a comment in your code referencing my name 
             *          AND display that part of the program which uses this code has a visual reference 
             *          to my name in an obvious location (like the About box).
             * 
             * Precondition: sText is a string in the non 2D virginia ID barcode format (see below).
             * Postcondition: Returns String array in the following format:
			 *                  {   [0]=>IDNumber,
			 *                      [1]=>BirthDateM,
             *                      [2]=>BirthDateD,
             *                      [3]=>BirthDateY,
             *                      [4]=>ExpiryDateM,
             *                      [5]=>ExpiryDateD,
             *                      [6]=>ExpiryDateY,
			 *                      [7]=>Age,
			 *                      [8]=>Exired }
             |* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *|
			 * Virginia ID barcode format:
			 *  000000000   0000000000000000
			 *  [ID number][spaces][birthday][expiry]
			 *  [XXXXXXXXX][---][YYYMMDD][YYYYMMDD]
			 *  [123121234][123][12341212][12341212] 
			\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

            String sIdNum; //A00-00-0000 format or SSN (000-00-0000)
			String sBirthDate; //YYYMMDD
			String sExpDate; //YYYMMDD

			int iBYear, iBMonth, iBDay; //birthday vars
			int iEYear, iEMonth, iEDay; //expiration vars
			int iAge; //years
			bool bExpired = true; //has the license expired?

            //The entire length of the string is 9+3+8+8=12+16=28
            // 0 + 9 = [9 + 3] = 12 + 8 = 20 (substrings to take)
			sIdNum = sText.Substring(0, 9); //ID number (there are no dashes stored)

			sBirthDate = sText.Substring(12, 8);
			iBYear = Convert.ToInt32(sBirthDate.Substring(0, 4));//we want these in integer values to make it easier to compute age
			iBMonth = Convert.ToInt32(sBirthDate.Substring(4, 2));
			iBDay = Convert.ToInt32(sBirthDate.Substring(6));

			sExpDate = sText.Substring(20);
			iEYear = Convert.ToInt32(sExpDate.Substring(0, 4)); //we need these as ints as well for the same reason as above (how "old" is the expiration date?)
			iEMonth = Convert.ToInt32(sExpDate.Substring(4, 2));
			iEDay = Convert.ToInt32(sExpDate.Substring(6));

			iAge = CurrentAge(iBYear,iBMonth,iBDay); //get age in whole years

			if(CurrentAge(iEYear,iEMonth,iEDay) < 0) //is the expiration date in the future (negative age)?
				bExpired = false;


            String[] sResults = { 
                Convert.ToString(sIdNum),
			    Convert.ToString(iBMonth),
		        Convert.ToString(iBDay),
				Convert.ToString(iBYear),
				Convert.ToString(iEMonth),
				Convert.ToString(iEDay),
				Convert.ToString(iEYear),
				Convert.ToString(iAge),
				Convert.ToString(bExpired)
            };//See comment above for human readable explination of this data structure.

			return sResults;
        }