简体   繁体   English

从字符串中删除隐藏的字符

[英]Remove the hidden characters from the string

I am trying to remove the mark up from the string like below 我正在尝试从字符串中删除标记,如下所示

 string name = results[i].ToString();
 var b = Regex.Replace(name, "<.*?>",string.Empty);

String name looks like &lt;div class="ExternalClassA6E"&gt;&lt;p&gt;​&lt;span&gt;GET6&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; 字符串name看起来像&lt;div class="ExternalClassA6E"&gt;&lt;p&gt;​&lt;span&gt;GET6&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;

When I debug I dont see any extra spl characters in the b. 当我调试时,在b中看不到任何额外的spl字符。 But when see in the application after it ran a ? 但是当在应用程序中看到运行它之后? at the front of the varaiable b like ?GET6. 在变量b的前面,例如?GET6。 Is there something special about the markups here? 这里的标记有什么特别之处吗?

I copied your text above and ran some tests on it, and it is indeed acting very strangely! 我在上面复制了您的文本,并对其进行了一些测试,它的行为确实非常奇怪! There appears to be an actual hidden character in your string that does not display in the editor, but does appear when the string is parsed or written to the console. 字符串似乎有一个实际的隐藏字符,字符不会在编辑器中显示,但在将字符串解析或写入控制台时才会出现。

To test what you were saying, I pasted your string in my editor and ran some code, and I also saw the ? 为了测试您在说什么,我将您的字符串粘贴到编辑器中并运行了一些代码,并且还看到了? character in the output. 输出中的字符。 So then I typed the same text and ran the same tests, and there's no ? 因此,我输入了相同的文本并运行了相同的测试,没有? there: 那里:

private static void Main()
{
    string copiedText = "&gt;​&lt;";
    string typedText  = "&gt;&lt;";

    Console.WriteLine("\nCopied Text Results\n" + "-------------------");
    Console.WriteLine("\nLength: " + copiedText.Length);
    Console.WriteLine("\nCharacters and ascii values:");
    Console.WriteLine(string.Join(", ",
        copiedText.Select(character => character + " = " + (int) character)));
    Console.WriteLine("\nString value:");
    Console.WriteLine(copiedText);
    Console.WriteLine("\nHtml Decoded value:");
    Console.WriteLine(HttpUtility.HtmlDecode(copiedText));

    Console.WriteLine(Environment.NewLine + new string('-', Console.WindowWidth));

    Console.WriteLine("\nTyped Text Results\n" + "------------------");
    Console.WriteLine("\nLength: " + typedText.Length);
    Console.WriteLine("\nCharacters and ascii values:");
    Console.WriteLine(string.Join(", ",
        typedText.Select(character => character + " = " + (int) character)));
    Console.WriteLine("\nString value:");
    Console.WriteLine(typedText);
    Console.WriteLine("\nHtml Decoded value:");
    Console.WriteLine(HttpUtility.HtmlDecode(typedText));

    GetKeyFromUser("\nDone! Press any key to exit...");
}

Output 产量

![在此处输入图片描述

I guess this isn't really an answer, so I'll delete it shortly, but maybe it will spark someone else to provide some feedback. 我想这并不是一个真正的答案,所以我会尽快删除它,但也许它会激发其他人提供一些反馈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM