如何在C#中匹配CSV值中的确切单词 [英] How to match exact word from CSV values in C#

查看:104
本文介绍了如何在C#中匹配CSV值中的确切单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从表中获得csv值的句子,如'PROVIDENT FUND,员工对PF,PF,员工PF的贡献'。现在我想匹配确切的单词'

I have sentence having csv values from table like 'PROVIDENT FUND,Employee Contribution to PF,PF,Employee PF ' .Now I want to match exact word '

Employee Contribution to PF



'在这句话中是否存在而不分割和映射每个值。因为这句话可能会增加。而且分裂和映射可能会降低性能。所以如何以简单的方式匹配精确的单词?



我尝试了什么:



我得到字符串值分裂后循环然后我映射。为此我做了两个for循环,其中外循环获取每行csv值行,然后在分割后循环csv字段。现在我想要没有for循环的适当解决方案,因为性能随着值的增加而减少内部和外部循环值。

如何解决这个问题?提前感谢......


' exist in this sentence or not without splitting and mapping each values .Because this sentence may increases .And with Splitting and mapping may decrease performance .So how to match exact word in simple way ?

What I have tried:

I get string values in loop after splitting then I mapped.For this I made two for loops in which outer loop gets every row csv values rows and then loop on csv field after splitting.Now i want proper solution for this without for loop as performance decreases as values increases in both inner and outer loop values.
How to resolve this?Thanks in advance ......

推荐答案

说实话,我使用现有的CSV阅读器:快速CSV阅读器 [ ^ ]很好。

然后你可以使用string.Contains找到你的匹配。
To be honest, I'd use an existing CSV reader: A Fast CSV Reader[^] is good.
You can then just use string.Contains to find your matches.

< br>

引用:

因为这句话可能会增加。而且拆分和映射可能会降低性能

Because this sentence may increases .And with Splitting and mapping may decrease performance

你写的这个吗?因为你知道另一种表现更好的方式吗?如果有,请编程。



- 简单的方法:使用标准函数获取句子并搜索给定的单词。在我已经进行了众筹中搜索基金,你会有一场比赛,但这是你想要的吗?您需要检查单词前后的空格,除非它是第一个或最后一个。它仍然是简单的方法。



- 拆分方法:你只用一次单词分割句子。每个列表条目都是一个单词,你只需要检查一个列表条目是否等于一个单词,没有特殊情况。



使用split方法。当您想到更好的方法时,请尝试并比较性能结果。并告诉我们。

Do you write this because you know another way that perform better ? if so, program it.

- Simple minded method: Take the sentence and search a given word using standard function. Search "fund" in "I have made a crowdfunding.", you will have a match, but is it what you want ? You need to check for spaces before and after the word unless it is the first or last one. Is it still the easy way.

- split method: you split the sentence in words only once. Each list entry is a word, you just have to check if a list entry is equal to a word or not, no special cases.

Use the split method. when you think of a better method, try it and compare the performance results. and tell us.


这篇关于如何在C#中匹配CSV值中的确切单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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