嗔秤戻幣�哉膵�云利匈嬉蝕湊蛸賜�塋床四衲���萩晦編報炎嘔囚^泡仟 ̄云利匈�《超噌�殻窟�嵌虜隆輓麈觚翹瀘卉韮�仍仍�。� 烏御危列
浪慕利 卦指云慕朕村 厘議慕尺 厘議慕禰 TXT畠云和墮 序秘慕杏 紗秘慕禰

VB2008貫秘壇欺娼宥(PDF鯉塀哂猟井)-及28嫗

梓囚徒貧圭�鮗� ○ 賜 ★ 辛酔堀貧和鍬匈��梓囚徒貧議 Enter 囚辛指欺云慕朕村匈��梓囚徒貧圭�鮗� ● 辛指欺云匈競何��
!!!!隆堋響頼��紗秘慕禰厮宴和肝写偬堋響��






Character Mapping 



A single character takes 16 bits of space�察�and the space that a string consumes depends on the  

number of characters in a buffer。 If a buffer is 10 characters long�察�then the entire buffer takes up  

160 bits of space。  

      A single character is 16 bits long so that a buffer can store text in a multitude of different  

formats。 The standardized length is due to a standard called Unicode。 

      Consider the character a。 Philosophically�察�how do you know that an a is an a�拭�For humans�察 �

that¨s easy because our brains are trained to recognize the curve and look of an a。 Now look at  

the Russian letter shown in Figure 3´10。 



Figure 3´10。 A Russian letter 



      What letter does Figure 3´10 show�拭�It looks like an H�察�right�拭�But paring it to the English  

language�察�it is an N。 The Russian language has its own set of letters�察�and someone has deter

mined that a Russian H is an English N。 Figure 3´11 is a mapping of the Russian letters to the  

English letters。 



Figure 3´11。 Mapping of Russian letters to English letters 


´´´´´´´´´´´´´´´´´´´´´´Page 90´´´´´´´´´´´´´´´´´´´´´´´

68        CH AP T E R   3   *    L E A R N IN G   AB OU T   ST R I N G   M A N I P U L AT IO N S   



                If I were learning Russian�察�I would want the mapping provided in Figure 3´11。 The mapping  

           gives me an idea of what each letter in Russian represents。 You could think of Figure 3´11 as a  

          lookup table。 The puter has the same sort of need�察�because a puter does not under

           stand letters。 A puter understands only numbers and thus uses lookup tables that map a  

           set of letters to a set of numbers。  

                There are many lookup tables�察�such as American Standard Code for Information Inter

           change ��ASCII��。 For example�察�using ASCII�察�the letter a maps to the number 97。 The problem  

          with ASCII is that it works well for English�察�but works horribly for other languages。 ASCII was  

           extended to deal with Western European languages�察�but still fails for languages such as Chinese�察 �

           Russian�察�and Arabic。 

                The solution chosen by  is Unicode。 Unicode is the definition of a set of lookup tables  

           that map to letters for all of the languages of the world。 

                For the most part�察�you will not have to concern yourself with the Unicode�察�because   

           manages everything transparently。 This was not the case many years ago�察�when programmers  

          had to manage the lookup tables themselves。 So consider yourself lucky that you did not expe

           rience this pain in developing multilingual applications。 



           Dealing with Languages and Cultures 



           Managing strings in  does not stop with Unicode。  is very innovative in that it under

           stands concepts such as culture and language�察�which are a reflection of how humans speak and  

          live。 The ideas of culture and language do not exist in other programming environments。 

                Consider Switzerland as an example。 Throughout Switzerland�察�there are mountains that  

          happen to separate four individual languages�此�German�察�Italian�察�Romansch�察�and French。 Even  

          with the four languages�察�the Swiss all trade the same currency and write numbers the same  

          way。 

                In previous programming environments�察�the language would be tied to a particular country。  

          This works fine for France�察�Germany�察�and the United States�察�but fails miserably for Canada�察 �

           Switzerland�察�Belgium�察�and India。 You need to separate language from culture�察�because multiple  

          languages are used in different cultures。 For example�察�Italian is spoken in Switzerland and Italy。  

           French is spoken in France�察�Switzerland�察�Luxembourg�察�and Canada。 German is spoken in  

           Germany�察�Switzerland�察�and Austria。  



           Setting Culture and Language in Windows 



          The Windows operating system allows you to set the culture and language of your puter�察 �

           regardless of the language in which Windows is operating。 Figure 3´12 shows an example。 

                The example in Figure 3´12 is running a German version of Windows in Switzerland。 The  

          language is English�察�and the culture is Canada。 It would seem that Windows would get confused�察 �

          but in fact�察�if you write your  application properly�察�multilanguage support is simple。 


´´´´´´´´´´´´´´´´´´´´´´Page 91´´´´´´´´´´´´´´´´´´´´´´´

                                           CH AP T E R   3   *    L E AR N IN G   AB O U T   ST R I N G   M A N I PU L A TI O N S  69 



Figure 3´12。 Setting the culture and language in Windows 



Parsing and Processing Numbers 



The culture and country bee important when interacting with numbers and dates that  

are stored as strings。 Imagine retrieving a string buffer with an embedded number and then  

attempting to perform an addition�察�as illustrated by Figure 3´13。 



             Variables a and b are 

             assigned buffers that 

               represent numbers 



 Dim a As String = ;1; 

Dim b As String = ;2; 

Dim c As String = a �� b                  Adding two buffers is a 

                                         concatenation operation 

      Variable c contains 

          the value 12 



Figure 3´13。 Performing arithmetic on numbers represented as strings can lead to unexpected results。 


´´´´´´´´´´´´´´´´´´´´´´Page 92´´´´´´´´´´´´´´´´´´´´´´´

70        CH AP T E R   3   *    L E A R N IN G   AB OU T   ST R I N G   M A N I P U L AT IO N S   



                Adding numbers is performing a mathematical operation。 When the add operation is  

           performed on strings�察�it always results in a buffer concatenation。 The add operation is a very  

           simple way to concatenate string buffers together。 

                However�察�concatenation is not the aim of the example。 The aim is to treat the strings as  

           numbers and then add the numbers so that c contains the value  3 ��1 �� 2 = 3��。 The rewritten  

           version of the example is shown in Figure 3´14。 This code parses a string into an integer。 



                   Integer is a value type�察�but  

                 recognizes the methods associated 

                with the value types that can be used 

                        to parse string buffers 



            Dim a As Integer = Integer。Parse�─�1;�� 

           Dim b As Integer = Integer。Parse�─�2;�� 

           Dim c As Integer = a �� b 



              Variable c contains          Variables a and b are assigned 

                   the value 3                 values that represent the 

                                                 parsed string buffers 



           Figure 3´14。 Parsing strings into integers before doing the arithmetic 



                The type Integer has a  Parse�┌� method that can be used to turn a string into an integer。  

           The parsing works only if the buffer is a valid number。 If the buffer contains letters or an invalid  

           number�察�an error will be generated。  

                If the code can cope with a failed string conversion�察�the solution used by the parsing  

           routines is to generate an exception that a program could process。 Alternatively�察�a fail´safe way  

           to parse a number is to use TryParse�┌��察�as in the following example。 



           Dim value As Integer 

           If Integer。TryParse�─�1;�察�value�� Then  

               。 。 。 

           End If 



                The TryParse�┌� method does not return an integer value�察�but instead returns a  Boolean  

           flag�察�indicating whether the buffer could be parsed。 If the return value is True�察�then the buffer  

           could be parsed�察�and the result is stored in the parameter value。 You can parse other number  

           types using the same techniqu
卦指朕村 貧匯匈 和匯匈 指欺競何 壘��0�� 家��0��
隆堋響頼��紗秘慕禰厮宴和肝写偬堋響��
梁椣戻幣�� 梁心弌傍議揖扮窟燕得胎��傍竃徭失議心隈才凪万弌誌育断蛍�輌臆惨軼僑〃�燕慕得珊辛參資誼持蛍才将刮襲潜��範寔亟圻幹慕得 瓜寡追葎娼得辛參資誼寄楚署衛、持蛍才将刮襲潜填��