简体   繁体   English

如何将字符串拆分为单词并获取c#中不同的单词?

[英]How to split strings to words and get the words that are different in c#?

I have 2 richTextBoxes.我有 2 个 RichTextBoxes。 The user has to type text to richTextBox2 from richTextBox1.用户必须将文本从richTextBox1 输入到richTextBox2。 When this is done, I want to do a correction, which shows (highlights for example) the different words, double spaces etc. I need to do this with words, because one wrong word equals one mistake.完成后,我想做一个更正,显示(例如突出显示)不同的单词,双空格等。我需要对单词进行此操作,因为一个错误的单词等于一个错误。

Thank you in advance!先感谢您!

String[] words = str.split(" "); 

will get you all of the words that are seperated by a space and put them in an array of Strings.将获得所有由空格分隔的单词并将它们放入字符串数组中。 then you can go over that array and check every word individually.然后你可以遍历该数组并单独检查每个单词。

is this what you are looking for?这是你想要的? more info on str.split(char c)有关str.split(char c) 的更多信息

If you want to find different words you can use diffplex library.如果你想找到不同的词,你可以使用 diffplex 库。 You will need to implement words highlights.您将需要实现单词突出显示。

For a list of possible solutions, you can look here有关可能的解决方案的列表,您可以查看这里

Word by word diff comparison of two strings in .NET .NET 中两个字符串的逐字差异比较

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM