我有以下几点:
The __animal__ jumped over the __object__
我想用 C# 编写一个简洁的方法,它返回animal
和object
. 没有正则表达式怎么能做到这一点?一个肮脏的解决方案是一个一个地遍历字符,直到找到 a__
然后构建一个字符串直到找到结束点__
- 但我正在寻找一种更优雅的方法。
如果您不想使用正则表达式,您将不得不以某种形式进行迭代。
string text = "The __animal__ jumped over the __object__";
List<string> words = text.Split(' ').ToList();
words = words.Where(x => x.StartsWith("__") && x.EndsWith("__")).ToList();
你可以使用 IEnumerable. 的扩展来搜索,就像上面一样。但该框架在技术上是迭代的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句