I have an application which uses clipboard. Users copy data from excel and paste it into my application.
However, sometimes my application cannot handle the data correctly (in production). But I cannot reproduce the problem. Because the spreadsheet user is using contains his own macro and I am not allowed to have his original spreadsheet, I am thinking to add code to dump the text in the clipboard completely to a log file, so that I can see if the data being pasted is in the correct format.
I am especially concerned with the control characters contained in the clipboard. Therefore I want to dump the string as literal. For example, if string in the clipboard contains '\t'
, I want to see "\t"
in the log file, instead of a tab. Is there a way to do this?
Alternatively I can log the text in the hex format. But it seems I need to first convert the string
to a char[]
and use System.Buffer.BlockCopy
to copy the char[]
to a byte[]
. And then print the byte[] using BitConverter.ToString()
. It works fine. But is there a better way (easier, no need to copy, no need to loop through every character) to do this? .Net does not have a build-in function for this?
I used this as reference: byte[] to hex string
Methods suggested there look a little bit "heavy".