Other than "/r/n" are there any other escape sequences being pasted when I copy rows from Excel?

StackOverflow https://stackoverflow.com/questions/23477265

  •  15-07-2023
  •  | 
  •  

Question

I'm currently working on a project that involves copying multiple rows of Excel and pasting them into a single column of a data grid.

Part of the pasting procedure involves firing an event for the paste and programmatically replacing invalid values in the clipboard with valid ones. However, for some reason, the error detection in the data grid is still firing on the valid value being used to replace the bad one.

Example:

String temp = Clipboard.GetText();
String[] rows = clipContents.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

String output = "";
foreach(String row in rows)
{
   if(someCollection.Contains(row))
       output += row + "\r\n"     //"VALID_THING" and passes
   else
       output += "VALID_THING" + "\r\n"    //Still getting caught as an error
}

Clipboard.SetText(output);

I know the paste event and the modifications fire before the error detection because I can wipe the clipboard clean in the event of a bad value and not have any error detected from the paste.

Was it helpful?

Solution

You can use Notepad++ (with the setting view>show symbol>show all characters)to view what is being copied and confirm, but when I copy multiple rows from Excel, the only other characters aside from the carriage return/line feed you mention are tab characters(\t).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top