Marshal.PtrToStringUTF8 Method

Definition

Overloads

PtrToStringUTF8(IntPtr)

Allocates a managed String and copies all characters up to the first null character from an unmanaged UTF-8 string into it.

PtrToStringUTF8(IntPtr, Int32)

Allocates a managed String and copies a specified number of bytes from an unmanaged UTF8 string into it.

PtrToStringUTF8(IntPtr)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

Allocates a managed String and copies all characters up to the first null character from an unmanaged UTF-8 string into it.

public:
 static System::String ^ PtrToStringUTF8(IntPtr ptr);
public static string? PtrToStringUTF8 (IntPtr ptr);
[System.Security.SecurityCritical]
public static string PtrToStringUTF8 (IntPtr ptr);
public static string PtrToStringUTF8 (IntPtr ptr);
static member PtrToStringUTF8 : nativeint -> string
[<System.Security.SecurityCritical>]
static member PtrToStringUTF8 : nativeint -> string
Public Shared Function PtrToStringUTF8 (ptr As IntPtr) As String

Parameters

ptr
IntPtr

nativeint

The address of the first character of the unmanaged string.

Returns

A managed string that holds a copy of the unmanaged string if the value of the ptr parameter is not null; otherwise, this method returns null.

Attributes

Remarks

PtrToStringUTF8 is useful for custom marshaling or for use when mixing managed and unmanaged code. Because this method creates a copy of the unmanaged string's contents, you must free the original string as appropriate. This method provides the opposite functionality of the Marshal.StringToCoTaskMemUTF8 methods.

See also

Applies to

PtrToStringUTF8(IntPtr, Int32)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

Allocates a managed String and copies a specified number of bytes from an unmanaged UTF8 string into it.

public:
 static System::String ^ PtrToStringUTF8(IntPtr ptr, int byteLen);
public static string PtrToStringUTF8 (IntPtr ptr, int byteLen);
[System.Security.SecurityCritical]
public static string PtrToStringUTF8 (IntPtr ptr, int byteLen);
static member PtrToStringUTF8 : nativeint * int -> string
[<System.Security.SecurityCritical>]
static member PtrToStringUTF8 : nativeint * int -> string
Public Shared Function PtrToStringUTF8 (ptr As IntPtr, byteLen As Integer) As String

Parameters

ptr
IntPtr

nativeint

The address of the first character of the unmanaged string.

byteLen
Int32

The number of bytes to copy.

Returns

A managed string that holds a copy of the unmanaged string if the value of the ptr parameter is not null; otherwise, this method returns null.

Attributes

Remarks

PtrToStringUTF8 is useful for custom marshaling or when mixing managed and unmanaged code. Because this method creates a copy of the unmanaged string's contents, you must free the original string as appropriate. This method provides the opposite functionality of the Marshal.StringToCoTaskMemUTF8 methods.

See also

Applies to