diff --git a/Core/InteropServices/SafeMemoryHandle.cs b/Core/InteropServices/SafeMemoryHandle.cs
index 70664421..33763614 100644
--- a/Core/InteropServices/SafeMemoryHandle.cs
+++ b/Core/InteropServices/SafeMemoryHandle.cs
@@ -98,6 +98,13 @@ namespace Vanara.InteropServices
/// A that represents this instance.
string ToString(int len, CharSet charSet = CharSet.Unicode);
+ /// Returns a that represents this instance.
+ /// The length.
+ /// Number of bytes preceding the string pointer.
+ /// The character set of the string.
+ /// A that represents this instance.
+ string ToString(int len, int prefixBytes, CharSet charSet = CharSet.Unicode);
+
///
/// Gets an enumerated list of strings from a block of unmanaged memory where each string is separated by a single '\0' character and is terminated by
/// two '\0' characters.
@@ -352,7 +359,18 @@ namespace Vanara.InteropServices
/// The length.
/// The character set of the string.
/// A that represents this instance.
- public string ToString(int len, CharSet charSet = CharSet.Unicode) => len == -1 ? StringHelper.GetString(handle, charSet) : StringHelper.GetString(handle, charSet, sz).Substring(0, len);
+ public string ToString(int len, CharSet charSet = CharSet.Unicode) => ToString(len, 0, charSet);
+
+ /// Returns a that represents this instance.
+ /// The length.
+ /// Number of bytes preceding the string pointer.
+ /// The character set of the string.
+ /// A that represents this instance.
+ public string ToString(int len, int prefixBytes, CharSet charSet = CharSet.Unicode)
+ {
+ var str = StringHelper.GetString(handle.Offset(prefixBytes), charSet, sz - prefixBytes);
+ return len == -1 ? str : str.Substring(0, len);
+ }
/// Returns an enumeration of strings from memory where each string is pointed to by a preceding list of pointers of length .
/// The count of expected strings.