locked
Concluding two strings as equal if both have the first few characters same RRS feed

  • Question

  • Hi,

    I have a requirement where in I need to find whether a given string is approximately equal to other strings based on the initial few characters.

    For eg:

    Lets say I have the following strings

    Do

    Done

    Doing

    Noise

    Now when I search for D I should get Do, Done and Doing.

    If I search for Don I should get only Done. Hope you got my point. I am basically searching for string that start with similar characters like we do in a text box. We type the first few characters and then string with similar starting names appear.

    Could some body help me here.

    Thursday, September 26, 2013 2:00 PM

Answers

  • public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); this.Loaded += MainPage_Loaded; } private List<string> words = new List<string>() { "Do", "Done", "Doing", "Noise" }; private void MainPage_Loaded(object sender, RoutedEventArgs e) { var query = "do"; var query2 = "Don"; var query3 = "n"; var search1 = this.Search(query); //"Do", "Done" and "Doing" var search2 = this.Search(query2); //"Done" var search3 = this.Search(query3); //"Noise" }

    public List<string> Search(string query)
            {
                var result = this.words.Where(a => a.ToLower().StartsWith(query.ToLower())).ToList();
                return result;
            }




    Thursday, September 26, 2013 4:25 PM