°Ë±¦Êé¿â > ÎÄѧÆäËûµç×ÓÊé > VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ) >

µÚ77²¿·Ö

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

С˵£º VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ) ×ÖÊý£º ÿҳ4000×Ö

°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡




¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡usable¡¡for¡¡binary¡¡streams£»¡¡so¡¡we¡¡need¡¡to¡¡implement¡¡a¡¡new¡¡interface¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡architecture¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡The¡¡examples¡¡that¡¡follow¡¡illustrate¡¡a¡¡very¡¡mon¡¡situation¡¡where¡¡an¡¡architecture¡¡worked¡¡and¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ideas¡¡of¡¡the¡¡architecture¡¡could¡¡be¡¡applied¡¡in¡¡the¡¡new¡¡context¡£¡¡What¡¡does¡¡not¡¡work¡¡is¡¡the¡¡actual¡¡implementa

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tion¡¡of¡¡the¡¡original¡¡architecture¡£¡¡You¡¡may¡¡be¡¡tempted¡¡to¡¡modify¡¡the¡¡working¡¡architecture¡¡so¡¡that¡¡it¡¡will¡¡work¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡with¡¡the¡¡new¡¡context¡£¡¡As¡¡much¡¡as¡¡you¡¡would¡¡like¡¡to¡¡do¡¡that£»¡¡don¡¯t¡£¡¡Often£»¡¡the¡¡abstractions¡¡you¡¡create¡¡will¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡plicate¡¡the¡¡architecture¡¡and¡¡make¡¡the¡¡resulting¡¡code¡¡more¡¡plex¡£¡¡Your¡¡challenge¡¡is¡¡to¡¡know¡¡when¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡generalize¡¡an¡¡architecture¡¡and¡¡when¡¡to¡¡keep¡¡the¡¡ideas¡¡of¡¡an¡¡architecture¡¡but¡¡create¡¡a¡¡new¡¡implementation£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡you¡¯ll¡¡learn¡¡this¡¡with¡¡experience¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Defining¡¡the¡¡Interfaces¡¡and¡¡Implementing¡¡the¡¡Shell¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡£»¡¡the¡¡data¡¡streams¡¡are¡¡split¡¡into¡¡two¡¡types¡¡of¡¡streams£º¡¡binary¡¡and¡¡text¡£¡¡The¡¡TextWriter¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡TextReader¡¡types¡¡are¡¡used¡¡to¡¡read¡¡text¡­based¡¡data¡¡streams¡£¡¡As¡¡was¡¡demonstrated¡¡with¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡StringReader¡¡type£»¡¡when¡¡dealing¡¡with¡¡text¡­based¡¡streams£»¡¡certain¡¡assumptions¡¡can¡¡be¡¡made£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡such¡¡as¡¡being¡¡able¡¡to¡¡find¡¡new¡¡lines¡¡in¡¡the¡¡stream¡£¡¡With¡¡binary¡¡data¡¡streams£»¡¡no¡¡such¡¡assump

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tions¡¡can¡¡be¡¡made¡£¡¡Binary¡¡streams¡¡have¡¡their¡¡own¡¡format£»¡¡which¡¡is¡¡known¡¡by¡¡only¡¡the¡¡program¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡doing¡¡the¡¡reading¡¡or¡¡writing¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡binary¡¡stream¡­based¡¡types¡¡can¡¡be¡¡used¡¡to¡¡process¡¡text¡¡data¡¡streams£»¡¡but¡¡doing¡¡so¡¡would¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡require¡¡knowing¡¡the¡¡details¡¡of¡¡the¡¡data¡¡stream¡£¡¡Remember¡¡that¡¡¡¡gives¡¡you¡¡a¡¡text¡­handling¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡system¡¡that¡¡understands¡¡the¡¡different¡¡Unicode¡¡code¡¡pages¡£¡¡A¡¡Unicode¡¡code¡¡page¡¡is¡¡a¡¡specific¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡translation¡¡map¡£¡¡If¡¡you¡¡decide¡¡to¡¡manipulate¡¡the¡¡text¡¡streams¡¡using¡¡binary¡¡stream¡¡types£»¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡telling¡¡¡¡that¡¡you¡¡will¡¡manage¡¡the¡¡details¡¡of¡¡the¡¡Unicode¡¡code¡¡pages¡£¡¡Of¡¡course£»¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡don¡¯t¡¡want¡¡to¡¡do¡¡that£»¡¡and¡¡thus¡¡should¡¡never¡¡mix¡¡data¡¡streams¡£¡¡So£»¡¡for¡¡our¡¡sample¡¡application£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡we¡¡need¡¡to¡¡design¡¡two¡¡different¡¡interfaces£º¡¡one¡¡to¡¡stream¡¡from¡¡text¡¡to¡¡binary¡¡and¡¡one¡¡to¡¡stream¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡from¡¡binary¡¡to¡¡text¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡For¡¡more¡¡information¡¡about¡¡Unicode¡¡and¡¡other¡¡text¡­related¡¡issues£»¡¡see¡¡the¡¡MSDN¡¡¡°International¡¡Text¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Display¡±¡¡section¡¡£¨http£º//msdn2¡£microsoft¡£/en¡­us/library/ms776131¡£aspx£©¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡is¡¡the¡¡binary¡­to¡­text¡¡data¡¡stream¡¡interface£»¡¡Binary2Text¡£IBinary2TextProcessor¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Imports¡¡System¡£IO¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Interface¡¡IBinary2TextProcessor¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub¡¡Process£¨ByVal¡¡input¡¡As¡¡Stream£»¡¡ByVal¡¡output¡¡As¡¡TextWriter£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Interface¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡293¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡271¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡IBinary2TextProcessor¡¡interface¡¡has¡¡a¡¡single¡¡method£»¡¡Process£¨£©£»¡¡which¡¡has¡¡two¡¡param

eters£º¡¡the¡¡binary¡¡stream¡¡and¡¡the¡¡text¡¡stream¡£¡¡The¡¡implementation¡¡of¡¡IBinary2TextProcessor¡¡¡¡

would¡¡be¡¡responsible¡¡for¡¡reading¡¡the¡¡data¡¡from¡¡the¡¡binary¡¡stream¡¡and¡¡saving¡¡data¡¡to¡¡the¡¡¡¡

text¡¡stream¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡text¡­to¡­binary¡¡interface£»¡¡IText2BinaryProcessor£»¡¡follows¡¡a¡¡similar¡¡interface¡¡design£»¡¡¡¡

except¡¡that¡¡the¡¡input¡¡and¡¡output¡¡stream¡¡types¡¡are¡¡reversed¡£¡¡¡¡



Imports¡¡System¡£IO¡¡



Public¡¡Interface¡¡IText2BinaryProcessor¡¡

¡¡¡¡¡¡¡¡Sub¡¡Process£¨ByVal¡¡input¡¡As¡¡TextReader£»¡¡ByVal¡¡output¡¡As¡¡Stream£©¡¡

End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡idea¡¡of¡¡both¡¡interface¡¡declarations¡¡is¡¡to¡¡focus¡¡on¡¡transferring¡¡data¡¡from¡¡one¡¡stream¡¡¡¡

to¡¡another¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡shell¡¡for¡¡both¡¡data¡¡stream¡¡interfaces¡¡is¡¡very¡¡similar¡¡to¡¡the¡¡shell¡¡of¡¡the¡¡text¡­processing¡¡¡¡

stream£»¡¡except¡¡that¡¡binary¡¡and¡¡text¡¡streams¡¡are¡¡involved¡£¡¡The¡¡TextProcessor¡¡shell¡¡was¡¡respon

sible¡¡for¡¡knowing¡¡if¡¡the¡¡data¡¡stream¡¡was¡¡from¡¡the¡¡console¡¡or¡¡from¡¡a¡¡file¡£¡¡When¡¡manipulating¡¡¡¡

binary¡¡streams£»¡¡the¡¡source¡¡still¡¡needs¡¡to¡¡be¡¡ascertained£»¡¡but¡¡instead¡¡of¡¡creating¡¡text¡¡streams£»¡¡¡¡

binary¡¡streams¡¡are¡¡created¡£¡¡If¡¡you¡¡understand¡¡the¡¡mechanics¡¡of¡¡using¡¡a¡¡text¡¡stream£»¡¡you¡¡will¡¡¡¡

understand¡¡the¡¡mechanics¡¡of¡¡using¡¡a¡¡binary¡¡stream¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡is¡¡the¡¡plete¡¡implementation¡¡of¡¡the¡¡text¡­to¡­binary¡¡bootstrap¡¡class¡£¡¡



Imports¡¡System¡£IO¡¡



Public¡¡Module¡¡Text2BinaryBootstrap¡¡

¡¡¡¡¡¡¡¡Public¡¡Sub¡¡DisplayHelp£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨You¡¡need¡¡help£¿¡¡Right¡¡now£¿¡¨£©¡¡

¡¡¡¡¡¡¡¡End¡¡Sub¡¡



¡¡¡¡¡¡¡¡Public¡¡Sub¡¡Start£¨ByVal¡¡args¡¡As¡¡String£¨£©£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡processor¡¡As¡¡IText2BinaryProcessor£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡#If¡¡DEBUG_OUTPUT¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Argument¡¡count£¨¡¨¡¡&¡¡args¡£Length¡¡&¡¡¡¨£©¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡Each¡¡argument¡¡As¡¡String¡¡In¡¡args¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Argument¡¡£¨¡¨¡¡&¡¡argument¡¡&¡¡¡¨£©¡¨£©¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡#End¡¡If¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡reader¡¡As¡¡TextReader¡¡=¡¡Nothing¡¡

·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨0£© ²È£¨1£©

Äã¿ÉÄÜϲ»¶µÄ