Search code examples
c#non-ascii-characters

Replace string with \ char not work in visual studio 2019


On my project I need to import from clipboard excel data.

But in case we have german chars like "ä ö ü" I need to replace:

clipboardText = Clipboard.GetText(TextDataFormat.Rtf);

clipboardText.Replace("\u252\'fc", "ü");

I got this error from compiler:

enter image description here


Solution

  • Add an @ in front of the " :

    clipboardText.Replace(@"\u252'fc", "ü");
    

    Or double the \\ :

    clipboardText.Replace("\\u252'fc", "ü");