请告诉我这个问题的答案...
string ss="pradeep rao having 2years exp";
在上面的字符串中我想找到年(或)年的单词,如果匹配单词,我会分开单词
string s="2";
string s1="years(or)year"
感谢 普拉迪普
答案 0 :(得分:3)
最简单的方法是使用正则表达式:
Regex = new Regex("(\d+)(years?)");
Match match = regex.Match(ss);
if(match.Success)
{
string s = match.Groups[1];
string s1 = match.Groups[2];
}
答案 1 :(得分:1)
没有解决方案,只是在正确的方向上提示:
答案 2 :(得分:0)
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;
}
}