什么是比较代码 [英] What is the code for comparison

查看:82
本文介绍了什么是比较代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在我的程序中输入名称时,在文本文件中计算相似度的代码是什么?



该程序是一个家谱,询问用户键入家庭成员的名字和姓氏,结果将计算文本文件中具有相同姓氏的成员列表,并在消息框中显示该金额。到目前为止,我在* .txt中有50个成员。

What is the code for counting the similarity within a text file when a user enter a name in my program?

The program is a family tree that ask the user to type the family member first and last name and the result will count the list of members that has the same last name within the text file and display the amount in a messagebox. So far I've 50 members within a *.txt.

推荐答案

int matchCount = File.ReadAllLines("filepath").Count(x => x.Contains("yourSearchstr"));
MessageBox.Show(matchCount.ToString());


原理图:



- 打开文本文件

- 逐行阅读并建立姓氏列表

- 然后你有一个姓氏列表,你可以用它们将能够写出类似

Schematically:

- Open the text file
- Read it line-by-line and build a list of last names
- You then have a list of last names, against which you will be able to write things like
int numberOfPeopleWithLastNameSnow = list.Where(s => s == "Snow").Count();



- 剩下的唯一部分就是决定如何处理用户输入。



祝你好运。随着更具体的问题会有更具体的答案。


- The only part left is deciding how you are going to handle user inputs.

Good luck. With more specific questions would come more specific answers.


这篇关于什么是比较代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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