C# 如何在c中特定字符串出现之前获取字符串的第一部分#

C# 如何在c中特定字符串出现之前获取字符串的第一部分#,c#,C#,我有一根绳子- <span style=\"font-weight: 800\">Residence, Effective Date: NA</span> <br />6367 US HIGHWAY 70 EAST<br />LA GRANGE NC 28551 <br /> 住所,生效日期:北卡罗来纳州拉格兰奇市东70号6367美国公路北卡罗来纳州28551号 我希望在第一次出现之前获取字符串的第一部分,并且所选部分应类似于- &

我有一根绳子-

<span style=\"font-weight: 800\">Residence, Effective Date: NA</span> <br />6367 US HIGHWAY 70 EAST<br />LA GRANGE NC 28551 <br />
住所,生效日期:北卡罗来纳州拉格兰奇市东70号6367美国公路
北卡罗来纳州28551号
我希望在第一次出现

之前获取字符串的第一部分,并且所选部分应类似于-

<span style=\"font-weight: 800\">Residence, Effective Date: NA</span>
住所,生效日期:NA
现在我做的就像-

string dictVal = "<span style=\"font-weight: 800\">Residence, Effective Date: NA</span> <br />6367 US HIGHWAY 70 EAST<br />LA GRANGE NC 28551 <br />";

                string[] items = dictVal.Split(new char[] { '<' },
                         StringSplitOptions.RemoveEmptyEntries);
                string firstPart = string.Join("<", items.Take(3));
string dictVal=“居住地,生效日期:北卡罗来纳州拉格兰奇北卡罗来纳州28551号北卡罗来纳州东部70号6367美国公路
”; string[]items=dictVal.Split(新字符[]{'只需使用和:

stringfirstpart=dictVal.Substring(0,dictVal.IndexOf(“
”)
如果您只想取第一部分,可以按以下方式使用:

using System.Text.RegularExpressions;

string dictVal= "< span style =\"font-weight: 800\">Residence, Effective Date: NA</span> <br />6367 US HIGHWAY 70 EAST<br />LA GRANGE NC 28551 <br />";
string first_value = Regex.Split(mystring, "<br />")[0]; //The 0 gets the first portion of the array, in this case it is the desired value

// And if you want to remove any spaces at the beginning and at the end of the string
string trim = first_value.Trim();
使用System.Text.regular表达式;
string dictVal=“住宅,生效日期:NA
6367美国70号公路东
北卡罗来纳州拉格兰奇28551
; string first_value=Regex.Split(mystring,“
”)[0];//0获取数组的第一部分,在本例中,它是所需的值 //如果要删除字符串开头和结尾的空格 string trim=第一个_值。trim();
什么不起作用?你能描述一下你看到的行为吗?
using System.Text.RegularExpressions;

string dictVal= "< span style =\"font-weight: 800\">Residence, Effective Date: NA</span> <br />6367 US HIGHWAY 70 EAST<br />LA GRANGE NC 28551 <br />";
string first_value = Regex.Split(mystring, "<br />")[0]; //The 0 gets the first portion of the array, in this case it is the desired value

// And if you want to remove any spaces at the beginning and at the end of the string
string trim = first_value.Trim();