diff --git a/src/TextCopy/WindowsClipboard.cs b/src/TextCopy/WindowsClipboard.cs index 6de25e05..e1e45496 100644 --- a/src/TextCopy/WindowsClipboard.cs +++ b/src/TextCopy/WindowsClipboard.cs @@ -149,7 +149,9 @@ static void TryOpenClipboard() Marshal.Copy(pointer, buff, 0, size); - return Encoding.Unicode.GetString(buff).TrimEnd('\0'); + var result = Encoding.Unicode.GetString(buff); + var nullCharIndex = result.IndexOf('\0'); + return nullCharIndex == -1 ? result : result[..nullCharIndex]; } finally {