我有一个字符串
“球棒和球不是笔,船不是电话”
我想选择与不相邻的词
例如——“不是笔”、“不是电话”
但是我做不到?我试图通过使用索引和子字符串来获取单词,但这是不可能的。
tempTerm = tempTerm.Trim().Substring(0, tempTerm.Length - (orterm.Length + 1)).ToString();
最佳答案
使用一些 Regex 怎么样?
有点像
string s = "bat and ball not pen or boat not phone";
Regex reg = new Regex("not\\s\\w+");
MatchCollection matches = reg.Matches(s);
foreach (Match match in matches)
{
string sub = match.Value;
}
参见 Learn Regular Expression (Regex) syntax with C# and .NET了解更多详情
关于c# - 如何在 C# 中找出句子中的下一个单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6757355/