我想从字符串中删除表情符号,但它不起作用
\n\nstring str = "Hello world \xe2\x98\x80\xe2\x9b\xbf"; \nstring result = Regex.Replace(str, @"\\p{Cs}", "");\nRun Code Online (Sandbox Code Playgroud)\n
我比较了我发现/想到的几个选项:
\n\nstring text = "Hello world \xe2\x98\x80\xe2\x9b\xbfEND";\n\nConsole.WriteLine(text);\nConsole.WriteLine(Regex.Replace(text, @"\\p{Cs}", ""));\nConsole.WriteLine(Regex.Replace(text, @"[^\\u0000-\\u007F]+", ""));\nConsole.WriteLine(text.Where(c => !Char.IsSurrogate(c)).ToArray());\nRun Code Online (Sandbox Code Playgroud)\n\n这就是结果:
\n\nHello world ??????END\nHello world ??END\nHello world END\nHello world ??END\nRun Code Online (Sandbox Code Playgroud)\n\n我不确定您的输入字符串在复制、粘贴到此处、再次复制并粘贴到 Visual Studio 后是否会在此过程中进行一些修改,但从我所看到的来看,显然第二个选项似乎效果更好。
\n\n您想删除所有特殊字符还是仅删除表情符号?
\n