다음을 통해 공유


String.GetBytes Method

Definition

Overloads

GetBytes(String)

Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array.

GetBytes()

Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.

GetBytes(Charset)

Encodes this String into a sequence of bytes using the given java.

GetBytes(Int32, Int32, Byte[], Int32)
Obsolete.

Copies characters from this string into the destination byte array.

GetBytes(String)

Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array.

[Android.Runtime.Register("getBytes", "(Ljava/lang/String;)[B", "")]
public byte[]? GetBytes (string charsetName);
[<Android.Runtime.Register("getBytes", "(Ljava/lang/String;)[B", "")>]
member this.GetBytes : string -> byte[]

Parameters

charsetName
String

The name of a supported java.nio.charset.Charset charset

Returns

Byte[]

The resultant byte array

Attributes

Exceptions

if the charset is not supported

Remarks

Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array.

The behavior of this method when this string cannot be encoded in the given charset is unspecified. The java.nio.charset.CharsetEncoder class should be used when more control over the encoding process is required.

Added in 1.1.

Java documentation for java.lang.String.getBytes(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

GetBytes()

Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.

[Android.Runtime.Register("getBytes", "()[B", "")]
public byte[]? GetBytes ();
[<Android.Runtime.Register("getBytes", "()[B", "")>]
member this.GetBytes : unit -> byte[]

Returns

Byte[]

The resultant byte array

Attributes

Remarks

Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.

The behavior of this method when this string cannot be encoded in the default charset is unspecified. The java.nio.charset.CharsetEncoder class should be used when more control over the encoding process is required.

Added in 1.1.

Java documentation for java.lang.String.getBytes().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

GetBytes(Charset)

Encodes this String into a sequence of bytes using the given java.

[Android.Runtime.Register("getBytes", "(Ljava/nio/charset/Charset;)[B", "")]
public byte[]? GetBytes (Java.Nio.Charset.Charset charset);
[<Android.Runtime.Register("getBytes", "(Ljava/nio/charset/Charset;)[B", "")>]
member this.GetBytes : Java.Nio.Charset.Charset -> byte[]

Parameters

charset
Charset

The java.nio.charset.Charset to be used to encode the String

Returns

Byte[]

The resultant byte array

Attributes

Remarks

Encodes this String into a sequence of bytes using the given java.nio.charset.Charset charset, storing the result into a new byte array.

This method always replaces malformed-input and unmappable-character sequences with this charset's default replacement byte array. The java.nio.charset.CharsetEncoder class should be used when more control over the encoding process is required.

Added in 1.6.

Java documentation for java.lang.String.getBytes(java.nio.charset.Charset).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

GetBytes(Int32, Int32, Byte[], Int32)

Caution

deprecated

Copies characters from this string into the destination byte array.

[Android.Runtime.Register("getBytes", "(II[BI)V", "")]
[System.Obsolete("deprecated")]
public void GetBytes (int srcBegin, int srcEnd, byte[]? dst, int dstBegin);
[<Android.Runtime.Register("getBytes", "(II[BI)V", "")>]
[<System.Obsolete("deprecated")>]
member this.GetBytes : int * int * byte[] * int -> unit

Parameters

srcBegin
Int32

Index of the first character in the string to copy

srcEnd
Int32

Index after the last character in the string to copy

dst
Byte[]

The destination array

dstBegin
Int32

The start offset in the destination array

Attributes

Exceptions

if data is null.

if start , end > length(), index or end - start > data.length - index.

Remarks

Copies characters from this string into the destination byte array. Each byte receives the 8 low-order bits of the corresponding character. The eight high-order bits of each character are not copied and do not participate in the transfer in any way.

The first character to be copied is at index srcBegin; the last character to be copied is at index srcEnd-1. The total number of characters to be copied is srcEnd-srcBegin. The characters, converted to bytes, are copied into the subarray of dst starting at index dstBegin and ending at index:

<blockquote>

dstBegin + (srcEnd-srcBegin) - 1

</blockquote>

This member is deprecated. This method does not properly convert characters into bytes. As of JDK&nbsp;1.1, the preferred way to do this is via the #getBytes() method, which uses the platform's default charset.

Java documentation for java.lang.String.getBytes(int, int, byte[], int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to