[英]Extracting parts of a string
I have a string Like SHD2018101 + SHD2018102 / 26
or it can be SHD2018101 + SHD2018102 / 26 + SHD2018103
.我有一个字符串 Like SHD2018101 + SHD2018102 / 26
或者它可以是SHD2018101 + SHD2018102 / 26 + SHD2018103
。 The string started with SHD is a database table key which is starting with SHD .以SHD开头的字符串是以SHD开头的数据库表键。 I have to separate the database table key and keep it in a array or in a list to get the value from database.我必须分离数据库表键并将其保存在数组或列表中以从数据库中获取值。
Thanks in advance.提前致谢。
Something like below should work:像下面这样的东西应该有效:
string subject = "SHD2018101 + SHD2018102 / 26 + SHD2018103";
StringCollection result = new StringCollection();
Regex regexObj = new Regex(@"(SHD\d+)");
Match matchResult = regexObj.Match(subject);
while (matchResult.Success) {
result.Add(matchResult.Groups[1].Value);
matchResult = matchResult.NextMatch();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.