首页 > 解决方案 > 检查字符串仅包含和 & 仅

问题描述

我有一个字符串,我只需要检查这个字符串只包含 &&

细绳

string oldStr ="       ";

我试过这样。

bool x = !string.IsNullOrWhiteSpace(oldStr);

标签: c#asp.net

解决方案


Given your string is HTML which has been HTML encoded, you need to HTML decode it twice.

string oldStr = "       ";

var result = HttpUtility.HtmlDecode(HttpUtility.HtmlDecode(oldStr));

Console.WriteLine(string.IsNullOrWhiteSpace(result)); 

This will output true (since a non-breaking space is whitespace).


推荐阅读