文字检查器 [英] Word checker

查看:49
本文介绍了文字检查器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何制作一个程序来检查同一单词中是否有2个.例如,如果我有一个文本:" 大象跳到 球上".在文本中有两个" the ",我想要的是程序应该告诉我何时有两个相同的单词……我不知道该怎么做.
谢谢.

How do I make a program that checks if there is 2 of the same word. For example if I have a text: "the elephant jumps on the ball". It is two " the " in the text and what I want is that the program should tell me when there is 2 of the same word... I have no clue how to do this.
Thank you.

推荐答案

也许将文本和气泡排序.
然后循环遍历,看看任何一个单词后跟有哪个单词.
突出显示该单词和宾果游戏!
Maybe take the text and bubble sort it.
Then loop through and see where any word is followed by the same word.
Highlight that word and Bingo!


示例:

字符串输入=大象跳到球上".ToLower();

string [] words = input.Split('''',''.'','','');

List< string> unikWords = new List< string>();
List< int> count = new List< int>();

foreach(字串值)
{
如果(unikWords.Contains(value))
{
int p = unikWords.IndexOf(value);
count [p] ++;
}
其他
{
unikWords.Add(value);
count.Add(1);
}
}

for(int i = 0; i< unikWords.Count; i ++)
{
如果(count [i]> 1)
MessageBox.Show(unikWords [i] +," + count [i] .ToString());
}
Example:

string input = "the elephant jumps on the ball".ToLower();

string[] words = input.Split('' '',''.'','','');

List<string> unikWords = new List<string>();
List<int> count = new List<int>();

foreach (string value in words)
{
if (unikWords.Contains(value))
{
int p = unikWords.IndexOf(value);
count[p]++;
}
else
{
unikWords.Add(value);
count.Add(1);
}
}

for (int i = 0; i < unikWords.Count; i++)
{
if (count[i] > 1)
MessageBox.Show(unikWords[i]+","+count[i].ToString());
}


Dictionary<string,int> dict= new Dictionary<string,int>();
string str = "the elephant jumps on the ball";
string [] a = str.Split(new char []{' '});
foreach( string s in a)
{
  if (dict.ContainsKey(s) )
     dict[s]++;
  else
     dict[s]=1;
}
foreach(string k in dict.Keys)
{
  if (dict[k] == 2) Console.WriteLine(k);
}


:)


这篇关于文字检查器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆