System.Text.ASCIIEncoding Class

public class ASCIIEncoding : Encoding

Base Types

Object
  Encoding
    ASCIIEncoding

Assembly

mscorlib

Library

BCL

Summary

Represents an ASCII character implementation of Encoding .

Description

ASCIIEncoding encodes characters as single 7-bit ASCII characters. This encoding supports Unicode code points between U+0000 and U+007F, inclusive.

[Note: The limited range of code points supported by ASCIIEncoding makes ASCII inadequate for many internationalized applications. UTF8Encoding and UnicodeEncoding provide encodings that are more suitable for internationalized applications.]

See Also

System.Text Namespace

Members

ASCIIEncoding Constructors

ASCIIEncoding Constructor

ASCIIEncoding Methods

ASCIIEncoding.GetByteCount(char[], int, int) Method
ASCIIEncoding.GetByteCount(System.String) Method
ASCIIEncoding.GetBytes(System.String, int, int, byte[], int) Method
ASCIIEncoding.GetBytes(char[], int, int, byte[], int) Method
ASCIIEncoding.GetCharCount Method
ASCIIEncoding.GetChars Method
ASCIIEncoding.GetMaxByteCount Method
ASCIIEncoding.GetMaxCharCount Method
ASCIIEncoding.GetString(byte[], int, int) Method
ASCIIEncoding.GetString(byte[]) Method


ASCIIEncoding Constructor

public ASCIIEncoding();

Summary

Constructs a new instance of the ASCIIEncoding class.

See Also

System.Text.ASCIIEncoding Class, System.Text Namespace

ASCIIEncoding.GetByteCount(char[], int, int) Method

public override int GetByteCount(char[] chars, int index, int count);

Summary

Determines the exact number of bytes required to encode the specified range of the specified array of characters as ASCII-encoded characters.

Parameters

chars
A Char array containing the characters to encode as ASCII-encoded characters.
index
A Int32 that specifies the first index of chars to encode.
count
A Int32 that specifies the number of elements in chars to encode.

Return Value

A Int32 containing the number of bytes required to encode the range in chars from index to index + count as ASCII-encoded characters.

Exceptions

Exception TypeCondition
ArgumentNullExceptionchars is null .
ArgumentOutOfRangeException index < 0.

-or-

count < 0.

-or-

index and count do not specify a valid range in chars (i.e. ( index + count) > chars.Length).

Description

[Note: This method overrides System.Text.Encoding.GetByteCount(System.Char[]).]

See Also

System.Text.ASCIIEncoding Class, System.Text Namespace

ASCIIEncoding.GetByteCount(System.String) Method

public override int GetByteCount(string chars);

Summary

Determines the exact number of bytes required to encode the specified string as ASCII-encoded characters.

Parameters

chars
A String to encode as ASCII-encoded characters.

Return Value

A Int32 containing the number of bytes required to encode chars as ASCII-encoded characters.

Exceptions

Exception TypeCondition
ArgumentNullExceptionchars is null .

Description

[Note: This method overrides System.Text.Encoding.GetByteCount(System.Char[]).]

See Also

System.Text.ASCIIEncoding Class, System.Text Namespace

ASCIIEncoding.GetBytes(System.String, int, int, byte[], int) Method

public override int GetBytes(string chars, int charIndex, int charCount, byte[] bytes, int byteIndex);

Summary

Encodes the specified range of the specified string into the specified range of the specified array of bytes as ASCII-encoded characters.

Parameters

chars
A String to encode as ASCII-encoded characters.
charIndex
A Int32 that specifies the first index of chars from which to encode.
charCount
A Int32 that specifies the number of elements in chars to encode.
bytes
A Byte array to encode.
byteIndex
A Int32 that specifies the first index of bytes to encode into.

Return Value

A Int32 whose value equals the number of bytes encoded into bytes as ASCII-encoded characters.

Exceptions

Exception TypeCondition
ArgumentException(bytes.Length - byteIndex) < charCount.

ArgumentNullExceptionchars is null .

-or-

bytes is null .

ArgumentOutOfRangeExceptioncharIndex < 0.

-or-

charCount < 0.

-or-

(chars.Length - charIndex) < charCount.

-or-

byteIndex < 0.

-or-

byteIndex > bytes.Length.

Description

Every Char object in chars that is encoded into bytes and that does not have an ASCII equivalent (i.e. has a code point greater than U+007f) will be encoded as a question mark ('?').

[Note: This method overrides System.Text.Encoding.GetBytes(System.Char[]).]

See Also

System.Text.ASCIIEncoding Class, System.Text Namespace

ASCIIEncoding.GetBytes(char[], int, int, byte[], int) Method

public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex);

Summary

Encodes the specified range of the specified array of characters into the specified range of the specified array of bytes as ASCII-encoded characters.

Parameters

chars
A Char array containing the characters to encode as ASCII-encoded characters.
charIndex
A Int32 that specifies the first index of chars to encode.
charCount
A Int32 that specifies the number of elements in chars to encode.
bytes
A Byte array to encode.
byteIndex
A Int32 that specifies the first index of bytes to encode into.

Return Value

A Int32 whose value equals the number of bytes encoded into bytes as ASCII-encoded characters.

Exceptions

Exception TypeCondition
ArgumentException(bytes.Length - byteIndex) < charCount.

ArgumentNullExceptionchars is null .

-or-

bytes is null .

ArgumentOutOfRangeExceptioncharIndex < 0.

-or-

charCount < 0.

-or-

(chars.Length - charIndex) < charCount.

-or-

byteIndex < 0.

-or-

byteIndex > bytes.Length.

Description

Every Char object in chars that is encoded into bytes and that does not have an ASCII equivalent (i.e. has a code point greater than U+007f) will be encoded as a question mark ('?').

[Note: This method overrides System.Text.Encoding.GetBytes(System.Char[]).]

See Also

System.Text.ASCIIEncoding Class, System.Text Namespace

ASCIIEncoding.GetCharCount Method

public override int GetCharCount(byte[] bytes, int index, int count);

Summary

Determines the exact number of characters that will be produced by decoding the specified range of the specified array of bytes as ASCII-encoded characters.

Parameters

bytes
A Byte array to decode as ASCII-encoded characters.
index
A Int32 that specifies the first index in bytes to decode.
count
A Int32 that specifies the number elements in bytes to decode.

Return Value

A Int32 whose value equals the number of characters a call to System.Text.ASCIIEncoding.GetChars(System.Byte[],System.Int32,System.Int32,System.Char[],System.Int32) will produce if presented with the specified range of bytes.

[Note: This value does not take into account the state in which the current instance was left following the last call to System.Text.ASCIIEncoding.GetChars(System.Byte[],System.Int32,System.Int32,System.Char[],System.Int32). This contrasts with System.Text.Decoder.GetChars(System.Byte[],System.Int32,System.Int32,System.Char[],System.Int32) , which maintains state information across calls.]

Exceptions

Exception TypeCondition
ArgumentNullExceptionbytes is null .
ArgumentOutOfRangeExceptionindex < 0.

-or-

count < 0.

-or-

(bytes.Length - index) < count.

Description

[Note: This method overrides System.Text.Encoding.GetCharCount(System.Byte[]).]

See Also

System.Text.ASCIIEncoding Class, System.Text Namespace

ASCIIEncoding.GetChars Method

public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex);

Summary

Decodes the specified range of the specified array of bytes into the specified range of the specified array of characters as ASCII-encoded characters.

Parameters

bytes
A Byte array to decode as ASCII-encoded characters.
byteIndex
A Int32 that specifies the first index of bytes from which to decode.
byteCount
A Int32 that specifies the number elements in bytes to decode.
chars
A Char array of characters to decode into.
charIndex
A Int32 that specifies the first index of chars to store the decoded bytes.

Return Value

A Int32 whose value equals the number of characters decoded into chars as ASCII-encoded characters.

Exceptions

Exception TypeCondition
ArgumentException(chars.Length - charIndex) < byteCount.

ArgumentNullExceptionbytes is null .

-or-

chars is null .

ArgumentOutOfRangeExceptionbyteIndex < 0.

-or-

byteCount < 0.

-or-

(bytes.Length - byteIndex) < byteCount.

-or-

charIndex < 0.

-or-

charIndex > chars.Length.

Description

[Note: This method overrides System.Text.Encoding.GetChars(System.Byte[]) .

System.Text.ASCIIEncoding.GetChars(System.Byte[],System.Int32,System.Int32,System.Char[],System.Int32) can be used to determine the exact number of characters that will be produced for a specified range of bytes. Alternatively, the System.Text.ASCIIEncoding.GetMaxCharCount(System.Int32) method can be used to determine the maximum number of characters that will be produced for a specified number of bytes, regardless of the actual byte values.

]

See Also

System.Text.ASCIIEncoding Class, System.Text Namespace

ASCIIEncoding.GetMaxByteCount Method

public override int GetMaxByteCount(int charCount);

Summary

Returns the maximum number of bytes required to encode the specified number of characters as ASCII-encoded characters, regardless of the actual character values.

Parameters

charCount
A Int32 that specifies the number of characters to encode as ASCII-encoded characters.

Return Value

A Int32 containing the maximum number of bytes required to encode charCount characters as ASCII-encoded characters.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptioncharCount &lt; 0.

Description

[Note: This method overrides System.Text.Encoding.GetMaxByteCount(System.Int32) .

Use this method to determine a minimum buffer size for byte arrays passed to the System.Text.ASCIIEncoding.GetBytes(System.Char[],System.Int32,System.Int32,System.Byte[],System.Int32) or System.Text.Encoding.GetBytes(System.Char[]) method for the current instance. Using this minimum buffer size can help ensure that buffer overflow exceptions do not occur.

]

See Also

System.Text.ASCIIEncoding Class, System.Text Namespace

ASCIIEncoding.GetMaxCharCount Method

public override int GetMaxCharCount(int byteCount);

Summary

Gets the maximum number of characters produced by decoding a specified number of bytes as ASCII-encoded characters, regardless of the actual byte values.

Parameters

byteCount
A Int32 that specifies the number of bytes to decode as ASCII-encoded characters.

Return Value

A Int32 containing the maximum number of characters that would be produced by decoding byteCount bytes as ASCII-encoded characters.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionbyteCount < 0.

Description

[Note: This method overrides System.Text.Encoding.GetMaxCharCount(System.Int32) .

Use this method to determine the minimum buffer size for character arrays passed to the System.Text.ASCIIEncoding.GetChars(System.Byte[],System.Int32,System.Int32,System.Char[],System.Int32) or the System.Text.Encoding.GetChars(System.Byte[]) methods. Using this minimum buffer size can help ensure that buffer overflow exceptions do not occur.

]

See Also

System.Text.ASCIIEncoding Class, System.Text Namespace

ASCIIEncoding.GetString(byte[], int, int) Method

public override string GetString(byte[] bytes, int byteIndex, int byteCount);

Summary

Decodes the specified range of the specified array of bytes as a string of ASCII-encoded characters.

Parameters

bytes
A Byte array to decode as ASCII-encoded characters.
byteIndex
A Int32 that specifies the first index of bytes from which to decode.

byteCount
A Int32 that specifies the number of elements in bytes to decode.

Return Value

A String object containing the decoded representation of the range in bytes from byteIndex to byteIndex + byteCount as ASCII-encoded characters.

Exceptions

Exception TypeCondition
ArgumentNullExceptionbytes is null .
ArgumentOutOfRangeExceptionbyteIndex < 0.

-or-

byteCount < 0.

-or-

(bytes.Length - byteIndex) < byteCount.

Description

[Note: This method overrides System.Text.Encoding.GetString(System.Byte[]).]

See Also

System.Text.ASCIIEncoding Class, System.Text Namespace

ASCIIEncoding.GetString(byte[]) Method

public override string GetString(byte[] bytes);

Summary

Decodes the specified array of bytes as a string of ASCII-encoded characters.

Parameters

bytes
A Byte array to decode as ASCII-encoded characters.

Return Value

A String containing the decoded representation of bytes as ASCII-encoded characters.

Exceptions

Exception TypeCondition
ArgumentNullExceptionbytes is null .

Description

[Note: This method overrides System.Text.Encoding.GetString(System.Byte[]).]

See Also

System.Text.ASCIIEncoding Class, System.Text Namespace