2013-03-18 31 views

回答

3

最简单的方法是用正则表达式,像这样:

Regex = new Regex("(\d+)(years?)"); 

Match match = regex.Match(ss); 
if(match.Success) 
{ 
    string s = match.Groups[1]; 
    string s1 = match.Groups[2]; 
} 
+0

海戴夫·塞克斯顿这里这个错误是显示 – 2013-03-18 10:17:33

+0

无法识别的转义序列系统。 Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(“(\ d +)(years?)”); – 2013-03-18 10:18:32

+0

雅在工作我用另一个\符号像(“(\\ d +(年?)”) – 2013-03-18 10:28:46

1

没有解决办法,但在正确的方向提示字:

  1. 在ss字符串中搜索文本字符串'years'。你会得到一个索引。 (例如21)
  2. 使用字符串ss的开始,直到索引查找数字。 (开始于21和工作方式回来)
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; 
       } 
      } 
+0

如何分割单词,如果假设我在字符串中使用10年 – 2013-03-18 10:15:52