如何使用C#将词汇表解析为数据库?(How to use C# to parse a glossary into database?)

编程入门 行业动态 更新时间:2024-10-26 12:27:46
如何使用C#将词汇表解析为数据库?(How to use C# to parse a glossary into database?)

这应该是一个简单的,但我是C#的初学者。

给出以下格式的词汇表:

aptitude ability, skill, gift, talent aqueous watery arguably maybe, perhaps, possibly, could be

我该如何解析它,并以以下格式插入数据库表:

TABLE: Term_Glossary ================================================ Term_Name | Term_Definition | ================================================ aptitude | ability, skill, gift, talent | ------------------------------------------------ aqueous | watery | ------------------------------------------------ arguably | maybe, perhaps, possibly, could be| ================================================

任何帮助将不胜感激 - 谢谢。

更新我意识到数据库结构简单/低效 - 但实际上,我的问题是使用C# 解析第一个示例中找到的文本类型的代码 。 谢谢。

This should be a simple one, but I'm a beginner with C#.

Given a glossary list in the following format:

aptitude ability, skill, gift, talent aqueous watery arguably maybe, perhaps, possibly, could be

How can I parse this, and insert into a database table in the format:

TABLE: Term_Glossary ================================================ Term_Name | Term_Definition | ================================================ aptitude | ability, skill, gift, talent | ------------------------------------------------ aqueous | watery | ------------------------------------------------ arguably | maybe, perhaps, possibly, could be| ================================================

Any help would be appreciated - thanks.

Update I realize the database structure is simple/inefficient - but really, the point of my question is the code to parse the kind of text found in the first example, using C#. Thanks.

最满意答案

在我看来,你会读取第一行,将其保存到变量,读取第二行,将其保存到第二个变量,然后插入表中Term_Name =第一个变量,以及Term_Definition =第二个变量。

所以你的逻辑就像:

StreamReader SR; string Term_Name; string Term_Definition SR = File.OpenText(filename); Term_Name = SR.ReadLine(); while(Term_Name != null) { Term_Definition = SR.ReadLine(); // make your database call here to insert with these two variables. I don't know what DB you are using. Term_Name = SR.ReadLine(); } SR.Close();

It looks to me like you would read the first line, save it to a variable, read the second line, save it to a second variable, then insert into the table where Term_Name = first variable, and Term_Definition = second variable.

So your logic would be like:

StreamReader SR; string Term_Name; string Term_Definition SR = File.OpenText(filename); Term_Name = SR.ReadLine(); while(Term_Name != null) { Term_Definition = SR.ReadLine(); // make your database call here to insert with these two variables. I don't know what DB you are using. Term_Name = SR.ReadLine(); } SR.Close();

更多推荐

本文发布于:2023-07-25 10:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1259990.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词汇表   如何使用   数据库   database   glossary

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!