Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quicker ways to search a C# List<String> for substrings

I currently have a list called regkey and a string called line_to_delete, which I obviously want to delete from the list. At the moment I'm searching through one element of the list at a time creating substrings as line_to_delete only represents part of the line that I want to delete but is uniquely identifiable within the list.

Anyway what I really need to do is make this more efficient, use fewer resources and be quicker, so are there any ways to do this?

like image 244
manemawanna Avatar asked Nov 04 '09 16:11

manemawanna


People also ask

How can I Search my computer faster?

To get to search home even faster, you can use the keyboard shortcut Windows logo key + S to open Search, or simply mouse hover on the illustration in the search box on the taskbar.

Why does searching in Windows take so long?

The reason for this is because your laptop typically has many files, and the more files there are to index, the longer it takes to complete the process. So, it makes sense to tell Windows to limit indexing only to specific locations. For instance, you can exclude certain directories or folders.

How do I Search for files on Windows 10?

Use the Taskbar Search Bar for a General Search Press the WIN key, or select the search bar from the bottom-left corner of the taskbar, near the Start button. Start typing the name of the file, app, or another item you're looking for, but don't press Enter just yet. The results appear instantly.

How do I quick Search words in Windows?

To open the Find pane from the Edit View, press Ctrl+F, or click Home > Find. Find text by typing it in the Search the document for…


1 Answers

Use lamba expressions if it's a List<string>:

list.RemoveAll(x => x.Contains(line_to_delete));
like image 177
Jamie Ide Avatar answered Nov 03 '22 01:11

Jamie Ide