[英]how to find the word and split the integer and characters in a string
Please tell me this question answer please ... 请告诉我这个问题的答案,请...
string ss="pradeep rao having 2years exp";
in the above string i want to find the word of years(or) year and if match the the word,i wnt split the word like 在上面的字符串中,我想查找年份(或年份)的单词,如果与单词匹配,我将拆分单词,例如
string s="2";
string s1="years(or)year"
thanks pradeep 谢谢pradeep
Easiest way would be with a regular expression like so: 最简单的方法是使用正则表达式,如下所示:
Regex = new Regex("(\d+)(years?)");
Match match = regex.Match(ss);
if(match.Success)
{
string s = match.Groups[1];
string s1 = match.Groups[2];
}
No solution but a hint in the right direction: 没有解决方案,只是朝着正确方向的提示:
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.