Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 查找某些文本并过滤掉其余文本_C#_Regex_Http - Fatal编程技术网

C# 查找某些文本并过滤掉其余文本

C# 查找某些文本并过滤掉其余文本,c#,regex,http,C#,Regex,Http,假设我有这个字符串(很大),我想过滤掉所有东西,除了我要找的东西。下面是我想要的一个例子: <strong>You</strong></font> <font size="3" color="#05ABF8"> <strong>Shook</strong></font> Me All <font size="3" color="#05ABF8"> <strong>Night</str

假设我有这个字符串(很大),我想过滤掉所有东西,除了我要找的东西。下面是我想要的一个例子:

<strong>You</strong></font> <font size="3" color="#05ABF8">
<strong>Shook</strong></font> Me All <font size="3" color="#05ABF8">
<strong>Night</strong></font> <font size="3" color="#05ABF8">
<strong>Long</strong></font> mp3</a></div>

震撼了我所有人
夜晚
Longmp3

正如你所看到的,所有这些之间都有文字。我想得到“你整晚都在摇我”,然后把剩下的拿走。我将如何完成这项工作?

假设您在发布的xml/html的末尾有有效的开始标记作为结尾

string value = XElement.Parse(string.Format("<root>{0}</root>", yourstring)).Value;
string value=XElement.Parse(string.Format(“{0}”,yourstring)).value;
或剥离Html的方法:

public static string StripHTML(this string HTMLText)
{
    var reg = new Regex("<[^>]+>", RegexOptions.IgnoreCase);
    return reg.Replace(HTMLText, "").Replace("&nbsp;", " ");
}
公共静态字符串StripHTML(此字符串为HTMLText)
{
var reg=new Regex(“]+>”,RegexOptions.IgnoreCase);
return reg.Replace(HTMLText,“”).Replace(“,”);
}

假设您在发布的xml/html的末尾有有效的开始标记

string value = XElement.Parse(string.Format("<root>{0}</root>", yourstring)).Value;
string value=XElement.Parse(string.Format(“{0}”,yourstring)).value;
或剥离Html的方法:

public static string StripHTML(this string HTMLText)
{
    var reg = new Regex("<[^>]+>", RegexOptions.IgnoreCase);
    return reg.Replace(HTMLText, "").Replace("&nbsp;", " ");
}
公共静态字符串StripHTML(此字符串为HTMLText)
{
var reg=new Regex(“]+>”,RegexOptions.IgnoreCase);
return reg.Replace(HTMLText,“”).Replace(“,”);
}

你可以使用下面的正则表达式:
>([\s|\w]+)你可以使用下面的正则表达式:
>([\s|\w]+)读这个和/或关于“mp3”,你也需要捕获它吗?@Maxim,是的,我也想要它。不管怎样,Mate的回答让我得到了我需要的帮助。以下是我发现的有用代码:
String result=Regex.Replace(htmldoc,@“]*>”,String.Empty)。谢谢。@user1667191是的,看起来不错,不用担心。读一下这个和/或和/或“mp3”怎么样,你也需要捕捉它吗?@Maxim,是的,我也想要。不管怎样,Mate的回答让我得到了我需要的帮助。以下是我发现的有用代码:
String result=Regex.Replace(htmldoc,@“]*>”,String.Empty)。谢谢。@user1667191是的,看起来不错,不用担心。您不应该使用LINQ2XML来解析html。您不应该使用LINQ2XML来解析html