You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dear All
I have try this code to copy some unicode text:
static void Main(string[] args)
{
if (Clipboard.ContainsText())
{
string st = "";
try
{
st = Clipboard.GetText();
Clipboard.SetText("");
Console.WriteLine(st);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
But when I copy a string like this:
"Little ghé thăm trường Đại học Quân đội Hoàng gia Saint-Jean (Royal Military College Saint-Jean) bên bờ sông Richelieu, nằm cách Montreal bốn mươi km về phía Nam"
to clipboard then when i run the program, the following error has been thrown:
"String conversion error: Illegal byte sequence encounted in the input."
What should I do to resolve this error?
My system is:
OpenSUSE Leap 15.1, KDE
Mono 5.10.1.47
MonoDevelop 7.8.3
The text was updated successfully, but these errors were encountered:
using System;
using System.Text;
namespace TestThr2
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Start");
string SampleText = "Little ghé thăm trường Đại học Quân đội Hoàng gia Saint-Jean (Royal Military College Saint-Jean) bên bờ sông Richelieu, nằm cách Montreal bốn mươi km về phía Nam";
System.Windows.Forms.Clipboard.SetText(SampleText);
Console.WriteLine("Text inserted");
if (System.Windows.Forms.Clipboard.ContainsText())
{
Console.WriteLine("Text exists");
string Txt_ = System.Windows.Forms.Clipboard.GetText();
Console.WriteLine("Text retrieved");
}
else
{
Console.WriteLine("Text not exists");
}
Console.WriteLine("Stop");
}
}
}
Test scenario:
Open Gedit and create new document.
Write some short text to the document using only latin letters.
Copy the text (Ctrl+A and Ctrl+C).
Paste the text (Ctrl+V) to end of the document.
At this step, in the document document the same text will be repeated.
Clear the document using Ctrl+A and Delete.
Run the code. The code runs without exception. On the console there will be Unicode text.
Paste the text using Ctrl+V to Gedit document.
At this step there will be Unicode text in Gedit.
Remove the line System.Windows.Forms.Clipboard.SetText(SampleText); from the code.
Compile and run the code again.
The text will be retrieved and written to the console.
Copy the text manually. In the Gedit press Ctrl+A followed by Ctrl+C.
Run the code one more time without modification and recompilation.
At this point the Exception on System.Windows.Forms.Clipboard.GetText() will occur.
What is the difference between text sent to clipboard using System.Windows.Forms.Clipboard.SetText(string) and copied manually using Ctrl+C, while both textes are exactly the same?
Dear All
I have try this code to copy some unicode text:
static void Main(string[] args)
{
if (Clipboard.ContainsText())
{
string st = "";
try
{
st = Clipboard.GetText();
Clipboard.SetText("");
Console.WriteLine(st);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
But when I copy a string like this:
"Little ghé thăm trường Đại học Quân đội Hoàng gia Saint-Jean (Royal Military College Saint-Jean) bên bờ sông Richelieu, nằm cách Montreal bốn mươi km về phía Nam"
to clipboard then when i run the program, the following error has been thrown:
"String conversion error: Illegal byte sequence encounted in the input."
What should I do to resolve this error?
My system is:
OpenSUSE Leap 15.1, KDE
Mono 5.10.1.47
MonoDevelop 7.8.3
The text was updated successfully, but these errors were encountered: