日期:2014-05-18  浏览次数:20713 次

这个简单的程序怎么做呢?
有两个文本框,一个输入一个输出,一个按钮实现查找文本框1的字符串,找到某个字符串后一那个单词然后输出,这个程序怎么实现呢?

------解决方案--------------------
先根据textbox1模糊查询一把 在把查询出来的值丢给textbox2
------解决方案--------------------
找到某个字符串后一那个单词然后输出?????
在什么地方找?
------解决方案--------------------
最佳方法是使用正则表达式:
string text = "One car red car blue car";
string pat = @"(\w+)\s+(car)";
// Compile the regular expression.
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
// Match the regular expression pattern against a text string.
Match m = r.Match(text);
int matchCount = 0;
while (m.Success) 
{
Console.WriteLine("Match"+ (++matchCount));
for (int i = 1; i <= 2; i++) 
{
Group g = m.Groups[i];
Console.WriteLine("Group"+i+"='" + g + "'");
CaptureCollection cc = g.Captures;
for (int j = 0; j < cc.Count; j++) 
{
Capture c = cc[j];
System.Console.WriteLine("Capture"+j+"='" + c + "', Position="+c.Index);
}
}
m = m.NextMatch();
}

这是使用例子,可以实现多个匹配,正则表达式在处理字符串方面的功能几乎是无限的!