.Net Runtime Library for Delphi
Close
_ASCIIEncoding Interface
Represents an ASCII character encoding of Unicode characters.
CNClrLib.Core.Intf._ASCIIEncoding

File: CNClrLib.Core.Intf.pas

Namespace: CNClrLib.Core.Intf

Syntax
Delphi
_ASCIIEncoding = dispinterface;
For more information about the definition of the constructors, properties and methods, see ASCIIEncoding Class .
For information about the extra methods defined in the interface, see Derived Methods and Base Interface Methods.

Example
Delphi

program ASCIIEncodingExample;

{$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, CNClrLib.Host, CNClrLib.Core, CNClrLib.Host.Helper; var ascii: _ASCIIEncoding; unicodeString, decodedString: String; Console : _Console; indexOfPi, indexOfSigma: Integer; encodedBytes: _ByteArray; I: Integer; begin try Console := CoConsole.CreateInstance; ascii := CoASCIIEncoding.CreateInstance; try unicodeString := 'This Unicode string contains two characters ' + 'with codes outside the ASCII code range, ' + 'Pi (\u03a0) and Sigma (\u03a3).'; Console.WriteLine_14('Original string:'); Console.WriteLine_14(unicodeString); // Save positions of the special characters for later reference. indexOfPi := TClrStringHelper.IndexOf(unicodeString, '\u03a0'); indexOfSigma := TClrStringHelper.IndexOf(unicodeString, '\u03a3'); // Encode string. encodedBytes := ascii.GetBytes_5(unicodeString); Console.WriteLine; Console.WriteLine_14('Encoded bytes:'); for I := 0 to encodedBytes.Length - 1 do Console.Write('[{0}]', encodedBytes[I]); Console.WriteLine; // Notice that the special characters have been replaced with // the value 63, which is the ASCII character code for '?'. Console.WriteLine; Console.WriteLine_15('Value at position of Pi character: {0}', encodedBytes[indexOfPi]); Console.WriteLine_15('Value at position of Sigma character: {0}', encodedBytes[indexOfSigma]); // Decode bytes back to string. // Notice missing Pi and Sigma characters. decodedString := ascii.GetString_1(encodedBytes); Console.WriteLine; Console.WriteLine_14('Decoded bytes:'); Console.WriteLine_14(decodedString); Console.ReadLine; finally ascii := nil; end; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. // The example displays the following output: // Original string: // This Unicode string contains two characters with codes outside the ASCII code ra // nge, Pi (?) and Sigma (S). // // Encoded bytes: // [84][104][105][115][32][85][110][105][99][111][100][101][32][115][116][114][105] // [110][103][32][99][111][110][116][97][105][110][115][32][116][119][111][32][99][ // 104][97][114][97][99][116][101][114][115][32][119][105][116][104][32][99][111][1 // 00][101][115][32][111][117][116][115][105][100][101][32][116][104][101][32][65][ // 83][67][73][73][32][99][111][100][101][32][114][97][110][103][101][44][32][80][1 // 05][32][40][63][41][32][97][110][100][32][83][105][103][109][97][32][40][63][41] // [46] // // Value at position of Pi character: 63 // Value at position of Sigma character: 63 // // Decoded bytes: // This Unicode string contains two characters with codes outside the ASCII code ra // nge, Pi (?) and Sigma (?).