请告诉我这个问题的答案请...
string ss="pradeep rao having 2years exp";
在上面的字符串中,我想找到年份(或)年份的单词,如果匹配该单词,我不想像这样拆分单词
string s="2";
string s1="years(or)year"
谢谢 pradeep
最简单的方法是使用像这样的正则表达式:
Regex = new Regex("(\d+)(years?)");
Match match = regex.Match(ss);
if(match.Success)
{
string s = match.Groups[1];
string s1 = match.Groups[2];
}
没有解决方案,但在正确的方向提示:
string ss = "pradeep rao having 2years exp";
string[] SPLIT = ss.split(' ');
for (int i = 0; i < SPLIT.Length; i++)
{
if (SPLIT[i].Contains("years") || SPLIT[i].Contains("year"))
{
//SPLIT[i] is the required word split it or use Substring property to get the desired result
break;
}
}