Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 C# 中对单词进行子字符串化?例如,这是我的句子“这是我们用作示例的示例摘要。”
我想要子字符串 2 字 =“这是”
一种简单的方法是使用string.Split()空格分割单词,取两个单词Enumerable.Take,然后再次将它们与空格连接:
string.Split()
Enumerable.Take
string firstTwoWords = string.Join(" ", text.Split().Take(2));
记得添加using System.Linq;
using System.Linq;
演示