在C#中删除字符串中的特定unicode字符

Joe*_*ang 0 c# unicode

我试图删除我的字符串中的特定unicode字符.假设我们有以下代码.

public static string RemoveVerticalLine(this string source, char nil = ' ')
        {
            var s = '\u+007C';
            return new string(source.Select(c => c == s ? nil : c).ToArray());
        }
Run Code Online (Sandbox Code Playgroud)

在样本中.我试图移除U + 007c(垂直线).但我不知道为什么VS告诉我错误too many characters in character literal.我错过了什么吗?

在此输入图像描述

SLa*_*aks 5

这不是C#转义序列的工作方式.

你需要写'\u007c'.

或者只使用实际角色:'|'.