English 中文(简体)
铺设处理
原标题:string handling
  • 时间:2011-01-26 07:36:30
  •  标签:
  • c#

我愿知道,如果我在一份文本中拥有一名官兵,那么检查某一方的扼杀是否恰当和正确的话是最好的方法。 我的字典中约有100 000个字,我只字要检查600个字。 我只是寻求最有效的方式。 我也应当首先储存所有雕像,然后处理它们。

Thanx

最佳回答

100k 不是太多的,因此,你只能把所有东西放在上。

哈希姆的考察是关键的基础,因此会迅速缓解。

例如,这在法典中如何考虑:

string[] lines = File.ReadAllLines(@"C:MyDictionary.txt");
HashSet<string> myDictionary = new HashSet<string>();
foreach (string line in lines)
{
  myDictionary.Add(line);
}

string word = "aadvark";
if (myDictionary.Contains(word))
{
  Console.WriteLine("There is an aadvark");
}
else
{
  Console.WriteLine("The aadvark is a lie");
}
问题回答

或许应当使用HashSet<string>。 如果你重新使用。 NET 3.5或更高。

仅将有效字句装上HashSet<string>,然后使用 每个候选人的,或利用一些固定操作者找到所有有效字眼。

例如:

// There are loads of ways of loading words from a file, of course
var valid = new HashSet<string>(File.ReadAllLines("dictionary.txt"));
var candidates = new HashSet<string>(File.ReadAllLines("candidate.txt"));

var validCandidates = candidates.Intersect(valid);
var invalidCandidates = candidates.Except(valid);

您也不妨使用对个案敏感的比较或类似的比较——使用<条码>规范Comparer的静态特性,以在适当情况下取到<条码>。 StringComparer 可查阅<代码>HashSet的构造。

如果你重新使用。 NET 2, 您可使用。 Dictionary<string, whatever> as a poor-man s set - basic use what each similar as the Value, and Justeck for keys.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签