Click here to Skip to main content
14,304,598 members
Rate this:
Please Sign up or sign in to vote.
See more:
I need to search among a list of string values, for e.g.,
[Bank A/c, Bank OD A/c, Cash in hand, Deposits, Sundry Debtors, Sundry Creditors, Miscellaneous, ...]

If I type 'Ba' in the search box, it must return me result set as:
[Bank A/c, Bank OD A/c]

or if I type 'or', it must return to me result set containing strings:
[Sundry Debtors, Sundry Creditors]

What I have tried:

1. [_typedName]+
2. _typedName+
3. _typedName*
Posted
Updated 18-Feb-16 2:43am
Rate this:
Please Sign up or sign in to vote.

Solution 1

I would strongly recommend to go through this

The 30 Minute Regex Tutorial[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Not Regex. There have too many patterns to match. Instead, try and adapt from this example:
using System;
using System.Collections.Generic;

public class Program
{
	public static void Main()
	{
		var list = new List<string>();
		list.Add("Bank A/cat");
		list.Add("Bank OD A/c");
		list.Add("Cash in hand");
		list.Add("Deposit");
		list.Add("Sundry Debtors");
		list.Add("Sundry Creditors");

        // Your search string here
        string search="or";		
			
		foreach (string element in list)
		{
			if (element.IndexOf(search) != -1)
			{
				Console.WriteLine(element);
			}
		}
	}
}
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100