How to change from data to string?

  • Thread starter Thread starter bob
  • Start date Start date
B

bob

What im doing is parsing through Word and copying certain
words/phrases. I need to be able to use some of the
things ive copied as strings. The way ive written the
code gives me an error and im not sure why.

string test;
System.Windows.Forms.IDataObject dataobj;
dataobj = System.Windows.Forms.Clipboard.GetDataObject();
test = dataobj.GetData
(System.Windows.Forms.DataFormats.Text).ToString();
Console.WriteLine("{0}", test);

dataobj.GetaData(System.Windows.... etc.. is all one line.

I tried to save what ive copied into the clipboard as
dataobj. and then used ToString() to convert it to a
string. But it doesnt work. The code compiles but i get
an error during the actual process. And I know what I
want to be copied is in the clipboard because Ive opened
up Word and then the clipboard and have seen what i
copied over so thats not the problem. Any ideas about
what ive done wrong? Or any suggestions about how id
save what i have in my clipboard as a string?

thanks
 
i just figured it out. a much simpler way. for anyone
interested all i had to write was....

string test = app.Selection.Range.Text.ToString();

moral of the story... dont over think. sometimes you
overlook the most obvious of solutions.
 
-----Original Message-----
i just figured it out. a much simpler way. for anyone
interested all i had to write was....

string test = app.Selection.Range.Text.ToString();

I don't know what is the "app".

I have used the follow way ,it can run.
What's the error happened when you use it?

Maybe you should add a reference to "System.Windows.Form"
because the project you have is a Console Application.

 
Back
Top