Visual Studio C EqualityInequality Symbols

 

A Sharp Delineation between Char and ANSIString

There are a few occurrences of Visual Studio C# that force the programmer to accept data in a character (char) format (as opposed to an ANSIString format). For example, the principal file reader statement StreamReader.ReadBlock places the data it reads from the file into a char array, not an ANSIString. Then the programmer immediately places the char data into an ANSIString array and carries on (see line SU0630 below). It is not clear why this limitation was imposed on the StreamReader construct.

              // Read a record from 'Masterfile.dta'. SU0626:      string[] strData = new string[2];              // Begin reading the file. SU0627:      w.ReadBlock(charRealBlock, 0, 38); SU0628:      ItemNo++; SU0629:      strData[0] = ItemNo.ToString(); SU0630:      strData[1] = new string(charRealBlock, 0, 38); // Convert char string to                                                             // ANSIString 

The ANSIString data type is highly sophisticated. There is a substring procedure that picks off any portion of a larger string and places it into another new string ” a wonderful aid in parsing, searching, and sorting. For example, line SU4025 below picks off nine characters in strTemp beginning at char 24 (where the first char in the string is char 0) and places them in string strSubStr. This is powerful programming. In line SU4026 these nine characters are compared with the nine characters in strTB3. There are no NULL characters in either string.

 SU4023:     vv.ReadBlock(charRealBlock, 0, 38); SU4024:     strTemp = new string(charRealBlock); // Convert char string to ANSIString              // 'strTemp' contains 42 chars because the 'new string' process copies             // all sets of '\' to the new string. SU4025:     strSubStr = strTemp.Substring(24,9); // 20 chars plus 4 extra '\' chars. SU4026:     if(strSubStr == strTB3) SU4027:     { SU4028:       MessageBox.Show("Match Filename " + strTB3 + " found in record #"                                + (zz+1).ToString() + " ."); SU4029:       strTB4 = strTB3; SU4030:       RecordFound++; SU4031:     } SU4032:     else 

From time to time, you may need the single-subscripted character array. The declaration looks like this:

 char[] charRealB = char[38]; 

where the name of the char array is charRealB. The char array can be reused over and over (that is, it need not be recreated each time you use it). You can place characters in the array to overwrite any characters that need rework , etc.

You will seldom need a double-subscripted character array (an array of arrays) in modern coding, but this is its declaration:

 char[ , ] charDoubleD = char[16,22]; 

With the advent of Visual Studio C# there is no need for your program to use character arrays. Learn to use the ANSIString arrays ” the power is yours.

 


Unlocking Microsoft C# V 2.0 Programming Secrets
Unlocking Microsoft C# V 2.0 Programming Secrets (Wordware Applications Library)
ISBN: 1556220979
EAN: 2147483647
Year: 2005
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net