ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡
¸»Ê¿¿µÐ¡ËµÍø ·µ»Ø±¾ÊéĿ¼ ¼ÓÈëÊéÇ© ÎÒµÄÊé¼Ü ÎÒµÄÊéÇ© TXTÈ«±¾ÏÂÔØ ¡ºÊղص½ÎÒµÄä¯ÀÀÆ÷¡»

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ51²¿·Ö

¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿! Èç¹û±¾ÊéûÓÐÔĶÁÍ꣬ÏëÏ´μÌÐø½Ó×ÅÔĶÁ£¬¿ÉʹÓÃÉÏ·½ "Êղص½ÎÒµÄä¯ÀÀÆ÷" ¹¦ÄÜ ºÍ "¼ÓÈëÊéÇ©" ¹¦ÄÜ£¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡even¡¡slightly£»¡¡you¡¡must¡¡instantiate¡¡a¡¡new¡¡object£»¡¡which¡¡would¡¡be¡¡the¡¡case¡¡if¡¡we¡¡used¡¡the¡¡=¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡À¡¡operators¡£¡¡The¡¡¡¡StringBuilder¡¡type¡¡is¡¡like¡¡String£»¡¡except¡¡the¡¡referenced¡¡text¡¡can¡¡be¡¡modified¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡Process£¨£©¡¡implementation£»¡¡the¡¡Do¡¡While¡¡loop¡¡calls¡¡the¡¡method¡¡Peek£¨£©£»¡¡which¡¡reads£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡but¡¡does¡¡not¡¡remove£»¡¡a¡¡character¡¡value¡¡from¡¡the¡¡stream¡£¡¡If¡¡there¡¡is¡¡nothing¡¡more¡¡to¡¡read£»¡¡a¡¡¡­1¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡value¡¡is¡¡returned¡£¡¡Otherwise£»¡¡data¡¡is¡¡available£»¡¡and¡¡the¡¡method¡¡¡¡ReadLine£¨£©¡¡can¡¡be¡¡called¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ReadLine£¨£©¡¡will¡¡read¡¡a¡¡buffer¡¡of¡¡characters¡¡until¡¡a¡¡newline¡¡or¡¡return¡¡character¡¡is¡¡encountered¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Having¡¡read¡¡a¡¡line¡¡of¡¡text£»¡¡it¡¡is¡¡split¡¡into¡¡the¡¡individual¡¡fields¡¡using¡¡the¡¡Split£¨£©¡¡method¡£¡¡The¡¡split¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡characters¡¡are¡¡the¡¡space¡¡and¡¡tab¡¡character¡¡£¨ControlChars¡£Tab£©¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡the¡¡Split£¨£©¡¡method¡¡returns£»¡¡the¡¡individual¡¡fields¡¡are¡¡assigned¡¡to¡¡the¡¡array¡¡splitUpText¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Those¡¡array¡¡elements¡¡are¡¡iterated¡¡and¡¡appended¡¡to¡¡the¡¡StringBuilder¡¡variable¡¡retval£»¡¡but¡¡each¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡element¡¡is¡¡surrounded¡¡by¡¡a¡¡set¡¡of¡¡brackets¡£¡¡The¡¡brackets¡¡provide¡¡a¡¡set¡¡of¡¡boundaries¡¡that¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡can¡¡inspect¡¡to¡¡see¡¡what¡¡data¡¡has¡¡been¡¡found¡£¡¡I¡¡include¡¡the¡¡brackets¡¡purely¡¡for¡¡debugging¡¡purposes¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Because¡¡I¡¡am¡¡trying¡¡to¡¡reformat¡¡the¡¡stream£»¡¡I¡¡append¡¡a¡¡newline¡¡character¡¡£¨ControlChars¡£NewLine£©¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡variable¡¡retval¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡all¡¡of¡¡the¡¡lines¡¡of¡¡text¡¡and¡¡fields¡¡within¡¡the¡¡lines¡¡of¡¡text¡¡are¡¡iterated£»¡¡a¡¡string¡¡represen

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tation¡¡of¡¡the¡¡StringBuilder¡¡instance¡¡is¡¡returned¡¡using¡¡the¡¡ToString£¨£©¡¡method¡£¡¡Running¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code¡¡shows¡¡how¡¡many¡¡fields¡¡each¡¡line¡¡of¡¡text¡¡has¡¡and¡¡how¡¡you¡¡should¡¡format¡¡the¡¡text¡¡file¡£¡¡This¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡gives¡¡you¡¡an¡¡understanding¡¡of¡¡how¡¡the¡¡file¡¡is¡¡structured¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡is¡¡sample¡¡output¡¡from¡¡the¡¡lotto¡£txt¡¡file¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡287¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡A¡¡PT¡¡E¡¡R¡¡¡¡¡¡1¡¡0¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡O¡¡U¡¡T¡¡¡¡P¡¡E¡¡R¡¡S¡¡IS¡¡T¡¡E¡¡N¡¡CE¡¡265¡¡



£¨2000¡£01¡£15£©£¨6£©£¨10£©£¨25£©£¨26£©£¨38£©£¨42£©£¨20£©¡¡

£¨2000¡£01¡£19£©£¨2£©£¨16£©£¨18£©£¨23£©£¨32£©£¨43£©£¨26£©¡¡

£¨2000¡£01¡£22£©£¨4£©£¨5£©£¨6£©£¨24£©£¨34£©£¨38£©£¨9£©¡¡

£¨2000¡£01¡£26£©£¨3£©£¨20£©£¨22£©£¨24£©£¨34£©£¨39£©£¨9£©¡¡

£¨2000¡£01¡£29£©£¨7£©£¨12£©£¨13£©£¨34£©£¨38£©£¨39£©£¨28£©¡¡

£¨2000¡£02¡£02£©£¨1£©£¨18£©£¨22£©£¨28£©£¨35£©£¨43£©£¨32£©¡¡

£¨2000¡£02¡£05£©£¨4£©£¨13£©£¨15£©£¨31£©£¨32£©£¨45£©£¨37£©¡¡

£¨2000¡£02¡£09£©£¨1£©£¨29£©£¨31£©£¨34£©£¨39£©£¨41£©£¨25£©¡¡

¡£¡£¡£¡¡

£¨2006¡­12¡­27£©£¨11£©£¨13£©£¨17£©£¨21£©£¨24£©£¨26£©£¨38£©£¨578199£©£¨735993£©£¨£©£¨£©¡¡

£¨2006¡­12¡­30£©£¨3£©£¨13£©£¨22£©£¨30£©£¨35£©£¨41£©£¨34£©£¨142968£©£¨472679£©£¨£©¡¡

£¨£©¡¡

£¨£©¡¡

£¨£©¡¡

£¨2007¡­01¡­03£©£¨5£©£¨24£©£¨37£©£¨39£©£¨41£©£¨44£©£¨9£©£¨049802£©£¨133875£©£¨£©£¨£©¡¡

£¨2007¡­01¡­06£©£¨3£©£¨7£©£¨23£©£¨27£©£¨30£©£¨32£©£¨38£©£¨687442£©£¨874814£©£¨£©£¨£©¡¡

£¨2007¡­01¡­10£©£¨7£©£¨9£©£¨13£©£¨23£©£¨35£©£¨37£©£¨25£©£¨039498£©£¨648301£©£¨£©£¨£©¡¡

£¨2007¡­01¡­13£©£¨3£©£¨17£©£¨22£©£¨37£©£¨39£©£¨43£©£¨34£©£¨968842£©£¨162860£©£¨£©£¨£©¡¡

£¨2007¡­01¡­17£©£¨12£©£¨16£©£¨27£©£¨33£©£¨37£©£¨41£©£¨24£©£¨663824£©£¨765917£©£¨£©£¨£©¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡sample¡¡output¡¡shows¡¡that¡¡we¡¡have¡¡the¡¡following¡¡items¡¡to¡¡fix£º¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡There¡¡are¡¡empty¡¡lines¡¡of¡¡text¡¡where¡¡no¡¡data¡¡has¡¡been¡¡defined¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Some¡¡lines¡¡of¡¡text¡¡have¡¡empty¡¡fields¡¡at¡¡the¡¡end¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Some¡¡fields¡¡have¡¡an¡¡incorrect¡¡date¡¡format¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Some¡¡dates¡¡have¡¡duplicates£»¡¡which¡¡need¡¡to¡¡be¡¡removed¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Some¡¡lines¡¡of¡¡text¡¡have¡¡too¡¡many¡¡fields¡£¡¡We¡¡need¡¡to¡¡figure¡¡out¡¡which¡¡fields¡¡we¡¡want¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡keep¡¡and¡¡which¡¡we¡¡can¡¡discard¡£¡¡



¡öNote¡¡¡¡When¡¡processing¡¡streams¡¡and¡¡cleaning¡¡them¡¡up£»¡¡it¡¡is¡¡important¡¡to¡¡take¡¡the¡¡stream¡¡apart¡¡first¡¡and¡¡¡¡

see¡¡what¡¡you¡¡are¡¡up¡¡against¡£¡¡Do¡¡not¡¡make¡¡assumptions¡¡until¡¡you¡¡have¡¡looked¡¡at¡¡the¡¡individual¡¡pieces¡¡of¡¡data¡£¡¡¡¡

Then¡¡you¡¡will¡¡be¡¡able¡¡to¡¡determine¡¡the¡¡steps¡¡you¡¡need¡¡to¡¡undertake¡¡to¡¡fix¡¡the¡¡stream¡£¡¡



Fixing¡¡the¡¡Stream¡¡



The¡¡final¡¡solution¡¡uses¡¡the¡¡same¡¡code¡¡used¡¡to¡¡parse¡¡the¡¡lines¡¡of¡¡text¡¡and¡¡individual¡¡fields£»¡¡as¡¡¡¡

follows¡¡£¨note£»¡¡however£»¡¡that¡¡we¡¡need¡¡the¡¡individual¡¡lines¡¡if¡¡the¡¡date¡¡format¡¡is¡¡correct£»¡¡so¡¡we¡¡¡¡

store¡¡each¡¡one¡¡in¡¡the¡¡lineOfText¡¡variable£©£º¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡288¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

266¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡0¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡P¡¡E¡¡R¡¡S¡¡IS¡¡TE¡¡N¡¡CE¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Class¡¡LottoTicketProcessor¡¡£º¡¡Implements¡¡IProcessor¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_dates¡¡As¡¡IList£¨Of¡¡String£©¡¡=¡¡New¡¡List£¨Of¡¡String£©£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¡¡¡£¡¡¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Function¡¡Process£¨ByVal¡¡input¡¡As¡¡String£©¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡IProcessor¡£Process¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡reader¡¡As¡¡TextReader¡¡=¡¡New¡¡StringReader£¨input£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡retval¡¡As¡¡StringBuilder¡¡=¡¡New¡¡StringBuilder£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Do¡¡While¡¡reader¡£Peek£¨£©¡¡¡¡¡­1¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡lineOfText¡¡As¡¡String¡¡=¡¡reader¡£ReadLine£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡splitUpText¡¡As¡¡String£¨£©¡¡=¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡lineOfText¡£Split£¨New¡¡Char£¨£©¡¡£û¡¨¡¡¡¨c£»¡¡ControlChars¡£Tab£ý£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡_dates¡£Contains£¨splitUpText£¨0£©£©¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Continue¡¡Do¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡splitUpText£¨0£©¡£Length¡¡=¡¡0¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Continue¡¡Do¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡splitUpText£¨0£©¡£Contains£¨¡¨¡­¡¨£©¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡dateSplit¡¡As¡¡String£¨£©¡¡=¡¡splitUpText£¨0£©¡£Split£¨New¡¡Char£¨£©¡¡£û¡¨¡­¡¨c£ý£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡newDate¡¡As¡¡String¡¡=¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dateSplit£¨0£©¡¡&¡¡¡¨¡£¡¨¡¡&¡¡dateSplit£¨1£©¡¡&¡¡¡¨¡£¡¨¡¡&¡¡dateSplit£¨2£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡_dates¡£Contains£¨newDate£©¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Continue¡¡Do¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_dates¡£Add£¨newDate£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡retval¡£Append£¨newDate£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡c1¡¡As¡¡Integer¡¡=¡¡0¡¡To¡¡7¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡retval¡£Append£¨¡¨¡¡¡¨¡¡&¡¡splitUpText£¨c1£©£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Next¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Else¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_dates¡£Add£¨splitUpText£¨0£©£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡retval¡£Append£¨lineOfText£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡retval¡£Append£¨ControlChars¡£NewLine£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Loop¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡retval¡£ToString£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Function¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¡¡¡£¡¡¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡In¡¡the¡¡downloadable¡¡source¡¡code£»¡¡the¡¡individual¡¡steps¡¡taken¡¡to¡¡clean¡¡up¡¡the¡¡data¡¡stream¡¡are¡¡demon

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡strated¡£¡¡For¡¡reference£»¡¡the¡¡intermediate¡¡development¡¡steps¡¡in¡¡the¡¡source¡¡code¡¡are¡¡called¡¡Process01£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡through¡¡¡¡Process05£¨£©¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡review¡¡how¡¡this¡¡code¡¡fixes¡¡the¡¡five¡¡problems¡¡we¡¡discovered¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡289¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡A¡¡PT¡¡E¡¡R¡¡¡¡¡¡1¡¡0¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡O¡¡U¡¡T¡¡¡¡P¡¡E¡¡R¡¡S¡¡IS¡¡T¡¡E¡¡N¡¡CE¡¡267¡¡



Empty¡¡Lines¡¡of¡¡Text¡¡



The¡¡following¡¡code¡¡removes¡¡the¡¡empty¡¡lines¡¡of¡¡text¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡splitUpText£¨0£©¡£Length¡¡=¡¡0¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Continue¡¡Do¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡



¡¡¡¡¡¡¡¡¡¡When¡¡¡¡lotto¡£txt¡¡was¡¡processed£»¡¡the¡¡output¡¡data¡¡stream¡¡generated¡¡a¡¡single¡¡field¡¡array¡¡for¡¡¡¡

an¡¡empty¡¡line¡£¡¡So£»¡¡we¡¡know¡¡that¡¡if¡¡the¡¡first¡¡field¡¡element¡¡has¡¡a¡¡length¡¡of¡¡zero£»¡¡the¡¡line¡¡of¡¡text¡¡¡¡

should¡¡be¡¡ignored¡£¡¡



Empty¡¡Fields¡¡and¡¡Too¡¡Many¡¡Fields¡¡



The¡¡next¡¡problem¡¡in¡¡our¡¡list¡¡is¡¡that¡¡some¡¡lines¡¡have¡¡empty¡¡text¡¡fields¡¡at¡¡the¡¡end¡£¡¡Solving¡¡this¡¡¡¡

problem¡¡would¡¡probably¡¡entail¡¡a¡¡solution¡¡similar¡¡to¡¡the¡¡previous¡¡one£»¡¡but¡¡you¡¡should¡¡think¡¡of¡¡¡¡

the¡¡big¡¡picture¡¡and¡¡understand¡¡that¡¡solving¡¡one¡¡problem¡¡might¡¡also¡¡solve¡¡another¡¡problem¡£¡¡In¡¡¡¡

this¡¡case£»¡¡solving¡¡the¡¡problem¡¡of¡¡the¡¡empty¡¡fields¡¡also¡¡helps¡¡solve¡¡the¡¡problem¡¡of¡¡having¡¡too¡¡¡¡

many¡¡fields¡£¡¡

¡¡¡¡¡¡¡¡¡¡Both¡¡of¡¡these¡¡problems¡¡are¡¡solved¡¡by¡¡knowing¡¡the¡¡data¡¡that¡¡is¡¡being¡¡manipulated¡£¡¡As¡¡you¡¯ve¡¡¡¡

seen£»¡¡the¡¡data¡¡stream¡¡assumes¡¡the¡¡following¡¡format£º¡¡date£»¡¡then¡¡lottery¡¡numbers¡¡1¡¡to¡¡6£»¡¡and¡¡then¡¡¡¡

the¡¡bonus¡¡number¡£¡¡The¡¡parts¡¡of¡¡the¡¡data¡¡stream¡¡that¡¡are¡¡not¡¡correct¡¡have¡¡the¡¡same¡¡format£»¡¡with¡¡¡¡

some¡¡extra¡¡information¡¡like¡¡replay¡¡number¡¡and¡¡empty¡¡fields¡£¡¡Thus£»¡¡the¡¡fix¡¡is¡¡to¡¡copy¡¡the¡¡date¡¡¡¡

and¡¡append¡¡the¡¡remaining¡¡fields£»¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡retval¡£Append£¨newDate£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡c1¡¡As¡¡Integer¡¡=¡¡0¡¡To¡¡7¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡retval¡£Append£¨¡¨¡¡¡¨¡¡&¡¡splitUpText£¨c1£©£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Next¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡first¡¡line¡¡of¡¡code¡¡appends¡¡the¡¡date¡¡to¡¡the¡¡StringBuilder¡¡buffer¡¡£¨retval£©¡£¡¡Then¡¡in¡¡the¡¡¡¡

For¡¡loop¡¡that¡¡follows£»¡¡a¡¡space¡¡and¡¡the¡¡fields¡¡0¡¡to¡¡7¡¡are¡¡copied¡¡to¡¡the¡¡StringBuilder¡¡buffer¡£¡¡



Incorrect¡¡Data¡¡Format¡¡



In¡¡some¡¡of¡¡the¡¡fields£»¡¡the¡¡date¡¡has¡¡a¡¡period¡¡separator£»¡¡in¡¡others£»¡¡it¡¡has¡¡a¡¡hyphen¡£¡¡The¡¡correct¡¡¡¡

format¡¡is¡¡a¡¡period£»¡¡and¡¡the¡¡code¡¡that¡¡fixes¡¡the¡¡date¡¡format¡¡is¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡splitUpText£¨0£©¡£Contains£¨¡¨¡­¡¨£©¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡dateSplit¡¡As¡¡String£¨£©¡¡=¡¡splitUpText£¨0£©¡£Split£¨New¡¡Char£¨£©¡¡£û¡¨¡­¡¨c£ý£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡newDate¡¡As¡¡String¡¡=¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dateSplit£¨0£©¡¡&¡¡¡¨¡£¡¨¡¡&¡¡dateSplit£¨1£©¡¡&¡¡¡¨¡£¡¨¡¡&¡¡dateSplit£¨2£©¡¡



¡¡¡¡¡¡¡¡¡¡A¡¡fix¡¡is¡¡needed¡¡if¡¡the¡¡first¡¡field¡¡contains¡¡a¡¡hyphen¡£¡¡The¡¡¡¡If¡¡statement¡¡tests¡¡for¡¡this¡¡using¡¡the¡¡¡¡

Contains£¨£©¡¡method¡£¡¡If¡¡a¡¡fix¡¡is¡¡needed£»¡¡the¡¡first¡¡field¡¡is¡¡separated¡¡again¡¡into¡¡three¡¡subfields£»¡¡where¡¡¡¡

each¡¡subfield¡¡represents¡¡a¡¡part¡¡of¡¡the¡¡date¡¡£¨year£»¡¡month£»¡¡day£©¡£¡¡Then¡¡those¡¡three¡¡subfields¡¡are¡¡¡¡

rebined¡¡and¡¡separated¡¡using¡¡the¡¡period¡¡and¡¡assigned¡¡to¡¡the¡¡variable¡¡newDate¡£¡¡



Duplicate¡¡Dates¡¡



The¡¡last¡¡problem¡¡that¡¡needs¡¡to¡¡be¡¡solved¡¡is¡¡having¡¡duplicate¡¡dates¡¡in¡¡the¡¡data¡¡stream¡£¡¡The¡¡¡¡

following¡¡code¡¡fixes¡¡this¡¡problem¡¡£¨the¡¡duplicate¡¡date¡¡code¡¡is¡¡bolded£©¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡290¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

268¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡0¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡P¡¡E¡¡R¡¡S¡¡IS¡¡TE¡¡N¡¡CE¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡_dates¡£Contains£¨splitUpText£¨0£©£©¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Continue¡¡Do¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡splitUpText£¨0£©¡£Length¡¡=¡¡0¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Continue¡¡Do¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡splitUpText£¨0£©¡£Contains£¨¡¨¡­¡¨£©¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡dateSplit¡¡As¡¡String£¨£©¡¡=¡¡splitUpText£¨0£©¡£Split£¨New¡¡Char£¨£©¡¡£û¡¨¡­¡¨c£ý£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡newDate¡¡As¡¡String¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dateSplit£¨0£©¡¡&¡¡¡¨¡£¡¨¡¡&¡¡dateSplit£¨1£©¡¡&¡¡¡¨¡£¡¨¡¡&¡¡dateSplit£¨2£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡_dates¡£Contains£¨newDate£©¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Continue¡¡Do¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_dates¡£Add£¨newDate£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡retval¡£Append£¨newDate£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡c1¡¡As¡¡Integer¡¡=¡¡0¡¡To¡¡7¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡retval¡£Append£¨¡¨¡¡¡¨¡¡&¡¡splitUpText£¨c1£©£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Next¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Else¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_dates¡£Add£¨splitUpText£¨0£©£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡retval¡£Append£¨lineOfText£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Of¡¡all¡¡the¡¡problems¡¡we¡¡needed¡¡to¡¡solve£»¡¡this¡¡is¡¡the¡¡trickiest£»¡¡because¡¡it¡¡required¡¡multiple¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡pieces¡¡of¡¡code¡¡in¡¡multiple¡¡places¡£¡¡The¡¡code¡¡processes¡¡the¡¡data¡¡stream¡¡and¡¡keeps¡¡a¡¡list¡¡of¡¡dates¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡date¡¡is¡¡added¡¡to¡¡the¡¡list¡¡only¡¡if¡¡the¡¡date¡¡does¡¡not¡¡exist¡¡in¡¡the¡¡list£»¡¡which¡¡is¡¡checked¡¡using¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Contains£¨£©¡¡method¡£¡¡The¡¡¡¡lists¡¡expose¡¡this¡¡method¡¡to¡¡verify¡¡if¡¡the¡¡object¡¡being¡¡passed¡¡to¡¡it¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡equals¡¡one¡¡of¡¡the¡¡list¡¡members¡£¡¡The¡¡way¡¡that¡¡most¡¡lists¡¡implement¡¡the¡¡method¡¡is¡¡to¡¡iterate¡¡each¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡method¡¡and¡¡call¡¡the¡¡Equals£¨£©¡¡method¡£¡¡The¡¡catch¡¡is¡¡that¡¡if¡¡you¡¡declare¡¡a¡¡custom¡¡type£»¡¡the¡¡¡¡Equals£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡method¡¡defaults¡¡to¡¡verifying¡¡if¡¡one¡¡reference¡¡value¡¡equals¡¡another¡£¡¡You¡¡would¡¡need¡¡to¡¡imple

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ment¡¡a¡¡custom¡¡¡¡Equals£¨£©¡¡method¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡When¡¡you¡¡encounter¡¡situations¡¡where¡¡you¡¡need¡¡to¡¡write¡¡multiple¡¡pieces¡¡of¡¡code¡¡in¡¡multiple¡¡places£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡is¡¡a¡¡sign¡¡that¡¡you¡¡are¡¡about¡¡to¡¡create¡¡code¡¡that¡¡is¡¡hard¡¡to¡¡maintain¡£¡¡You¡¡should¡¡take¡¡a¡¡close¡¡look¡¡at¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code£»¡¡and¡¡If¡¡possible£»¡¡rewrite¡¡it¡£¡¡Of¡¡course£»¡¡this¡¡depends¡¡on¡¡a¡¡lot¡¡of¡¡factors¡£¡¡So¡¡sometimes£»¡¡you¡¡will¡¡need¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡just¡¡write¡¡the¡¡code£»¡¡test¡¡it£»¡¡and¡¡hope¡¡that¡¡it¡¡works¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡With¡¡the¡¡final¡¡solution£»¡¡the¡¡console¡¡application¡¡TextProcessor¡¡is¡¡plete¡£¡¡You¡¡could¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡process¡¡lotto¡£txt¡¡and¡¡get¡¡a¡¡correctly¡¡formatted¡¡data¡¡stream¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Piping¡¡Binary¡¡Data¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡working¡¡with¡¡the¡¡console£»¡¡for¡¡the¡¡most¡¡part£»¡¡you¡¡will¡¡be¡¡transferring¡¡text¡¡data¡¡from¡¡one¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡process¡¡to¡¡another¡¡or¡¡from¡¡one¡¡file¡¡to¡¡another¡¡file¡£¡¡However£»¡¡when¡¡developing¡¡in¡¡£»¡¡working¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡291¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡A¡¡PT¡¡E¡¡R¡¡¡¡¡¡1¡¡0¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡O¡¡U¡¡T¡¡¡¡P¡¡E¡¡R¡¡S¡¡IS¡¡T¡¡E¡¡N¡¡CE¡¡269¡¡



with¡¡text¡¡is¡¡not¡¡always¡¡the¡¡best¡¡choice¡£¡¡A¡¡more¡¡efficient¡¡approach¡¡might¡¡be¡¡to¡¡store¡¡the¡¡data¡¡in¡¡¡¡

a¡¡binary¡¡format¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡The¡¡easiest¡¡way¡¡to¡¡understand¡¡the¡¡difference¡¡between¡¡text¡¡data¡¡and¡¡binary¡¡data¡¡is¡¡to¡¡open¡¡¡¡

a¡¡binary¡¡file¡¡using¡¡a¡¡text¡¡editor£»¡¡as¡¡shown¡¡in¡¡Figure¡¡10¡­8¡£¡¡



Figure¡¡10¡­8¡£¡¡A¡¡binary¡¡file¡¡in¡¡a¡¡text¡¡editor¡¡



¡¡¡¡¡¡¡¡¡¡¡¡In¡¡Figure¡¡10¡­8£»¡¡you¡¡see¡¡just¡¡a¡¡bunch¡¡of¡¡funny¡¡characters¡¡with¡¡some¡¡text¡¡scattered¡¡throughout¡£¡¡¡¡

A¡¡binary¡¡file¡¡is¡¡different¡¡from¡¡a¡¡text¡¡file¡¡in¡¡that¡¡the¡¡format¡¡of¡¡a¡¡binary¡¡file¡¡is¡¡whatever¡¡the¡¡program¡¡¡¡

that¡¡reads¡¡and¡¡writes¡¡the¡¡binary¡¡data¡¡decides¡£¡¡The¡¡advantage¡¡of¡¡using¡¡a¡¡binary¡¡file¡¡is¡¡that¡¡you¡¡¡¡

can¡¡create¡¡plex¡¡structures¡£¡¡The¡¡disadvantage¡¡is¡¡that¡¡only¡¡the¡¡developer¡¡of¡¡the¡¡reader/writer¡¡¡¡

program¡¡knows¡¡what¡¡the¡¡file¡¡contains¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡Binary¡¡files¡¡are¡¡not¡¡always¡¡smaller£»¡¡but¡¡they¡¡are¡¡more¡¡efficient¡¡because¡¡you¡¡do¡¡not¡¡need¡¡to¡¡¡¡

parse¡¡and¡¡process¡¡the¡¡data¡£¡¡For¡¡example£»¡¡in¡¡the¡¡text¡­based¡¡lottery¡¡data¡¡stream¡¡reader£»¡¡we¡¡needed¡¡¡¡

to¡¡parse¡¡every¡¡single¡¡line¡¡and¡¡then¡¡split¡¡the¡¡line¡¡of¡¡text¡¡into¡¡individual¡¡fields£»¡¡which¡¡were¡¡then¡¡¡¡

parsed¡¡as¡¡integers¡¡and¡¡assigned¡¡to¡¡a¡¡variable¡£¡¡Using¡¡a¡¡binary¡¡file£»¡¡you¡¡only¡¡need¡¡to¡¡create¡¡a¡¡¡¡

binary¡¡type£»¡¡and¡¡read¡¡or¡¡write¡¡that¡¡type¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡In¡¡this¡¡section£»¡¡we¡¡will¡¡continue¡¡with¡¡the¡¡example¡¡of¡¡the¡¡lottery¡­prediction¡¡application£»¡¡but¡¡¡¡

this¡¡time£»¡¡create¡¡it¡¡as¡¡a¡¡console¡¡application¡¡that¡¡converts¡¡a¡¡text¡¡data¡¡stream¡¡into¡¡a¡¡binary¡¡data¡¡¡¡

stream¡¡and¡¡then¡¡back¡¡to¡¡a¡¡text¡¡stream¡£¡¡You¡¯ll¡¡see¡¡how¡¡you¡¡can¡¡pipe¡¡the¡¡data¡¡from¡¡one¡¡stream¡¡to¡¡¡¡

another¡¡by¡¡sending¡¡it¡¡from¡¡one¡¡application¡¡to¡¡another¡¡application¡£¡¡When¡¡we¡¡are¡¡finished¡¡¡¡

building¡¡this¡¡application£»¡¡the¡¡following¡¡mand¡¡line¡¡will¡¡be¡¡valid¡£¡¡



type¡¡lotto¡£txt¡¡£ü¡¡TextProcessor¡£exe¡¡£ü¡¡Text2Binary¡£exe¡¡£ü¡¡Binary2Text¡£exe¡¡



¡¡¡¡¡¡¡¡¡¡¡¡The¡¡mand¡¡line¡¡starts¡¡with¡¡generating¡¡a¡¡text¡¡data¡¡stream¡¡using¡¡the¡¡type¡¡mand¡£¡¡¡¡

The¡¡mand¡¡TextProcessor¡£exe¡¡generates¡¡a¡¡clean¡¡data¡¡stream¡¡that¡¡is¡¡then¡¡piped¡¡into¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡292¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

270¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡0¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡P¡¡E¡¡R¡¡S¡¡IS¡¡TE¡¡N¡¡CE¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Text2Binary¡£exe£»¡¡which¡¡generates¡¡a¡¡binary¡¡data¡¡stream¡£¡¡Finally£»¡¡the¡¡binary¡¡data¡¡stream¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡converted¡¡back¡¡into¡¡a¡¡text¡¡stream¡¡using¡¡Binary2Text¡£exe£»¡¡which¡¡displays¡¡the¡¡data¡¡on¡¡the¡¡console¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡architecture¡¡of¡¡TextProcessor¡¡with¡¡its¡¡implementation¡¡of¡¡the¡¡¡¡IProcessor¡¡interface¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡a¡¡general¡¡architecture¡¡of¡¡grabbing¡¡a¡¡file¡¡or¡¡console¡¡input/output¡¡stream¡¡worked¡£¡¡However£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡IProcessor¡¡is¡¡not¡¡usa
·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨11£© ²È£¨11£©
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿!
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾­Ñé½±Àø£¬ÈÏÕæдԭ´´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾­Ñé½±ÀøŶ£¡