Find letter combination on phone keypad

NotABot

I'm working on an app which is a dialer and I want to search contacts when user presses keys. I want to search contacts which match phone number as well as name of contact. I've implemented method to search contact based on phone number, when user presses key, it'll search the number similar to the keys pressed.

My code is:

List<string> a = new List<string>();
var alphabet = "abc";
var al2 = "def";

var q = alphabet.Select(x => x.ToString());
int size = 3;
for (int i = 0; i < size - 1; i++)
    q = q.SelectMany(x => al2, (x, y) => x + y);

foreach (var item in q)
    a.Add(item);

SearchListbox.ItemsSource = listobj
    .FindAll(x => x.Phone.Contains(str) || 
        x.FirstName.Contains(a.Any().ToString()));

It works perfectly for number search but not for name search.

I want to search contacts which match letter combinations when user presses keys. How do I do that? I'm building an app for windows phone so it must be in c#.

DLeh

this is a good job for regular expressions! here's an example i whipped up to use regex to search through:

        var names = new List<string>();
        names.Add("alice");
        names.Add("bob");
        names.Add("charlie");

        var digitMap = new Dictionary<int, string>()
        {
            { 1, "" },
            { 2, "[abcABC]" },
            { 3, "[defDEF]" },
            { 4, "[ghiGHI]" },
            { 5, "[jklJKL]" },
            { 6, "[mnoMNO]" },
            { 7, "[pqrsPQRS]" },
            { 8, "[tuvTUV]" },
            { 9, "[qxyzQXYZ]" },
            { 0, "" },
        };

        var enteredDigits = "26";
        var charsAsInts = enteredDigits.ToCharArray().Select(x => int.Parse(x.ToString()));

        var regexBuilder = new StringBuilder();
        foreach (var val in charsAsInts)
            regexBuilder.Append(digitMap[val]);

        var pattern = regexBuilder.ToString();

        //append a ".*" to the end of the regex to make it "StartsWith", beginning for "EndsWith", or both for "Contains";
        pattern = ".*" + pattern + ".*";

        var matchingNames = names.Where(x => Regex.IsMatch(x, pattern));

        Console.WriteLine("Matching input: " + enteredDigits + " as regex: " + pattern);

        foreach (var n in matchingNames)
            Console.WriteLine(n);

In this example, I had "26" as the input, which filters out all but "bob". If you remove the 6 you'll find it returns all three, as they all have a, b, or c in their names.

FYI, if you wanted it to match the number as well, simply add the number to the regex string value in the dictionary.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Find letter combination on phone keypad

From Dev

How do I find a combination of a letter a number in a VBA string?

From Dev

Android : TYPE_CLASS_PHONE keypad issue

From Dev

Creating JavaScript Phone Keypad with Alphabet for SMS

From Dev

Creating JavaScript Phone Keypad with Alphabet for SMS

From Dev

Combination of a letter using recursive

From Dev

Python: Every possible letter combination

From Dev

Batch to find a string of number&letter combination only in first 10 characters (in a txt file) per row and print the whole row

From Dev

Batch to find a string of number&letter combination only in first 10 characters (in a txt file) per row and print the whole row

From Dev

generate random letter and fixed number combination

From Dev

How to match letter combination and it's occurences

From Dev

regex to remove ANY number/letter combination?

From Dev

vim - Prefix number to 3 letter combination bdw

From Dev

Python: print possible letter combination of key size

From Dev

vim - Prefix number to 3 letter combination bdw

From Dev

regex to remove ANY number/letter combination?

From Dev

Map letter-number combination into command in vim

From Dev

How to find name of key for use in ~/.XCompose? (specifically keypad plus and minus)

From Dev

Mongoose find on field combination

From Dev

Find Random BitshiftRight Combination

From Dev

Find combination of groups and letters

From Dev

Ruby find combination

From Dev

Find a selector starting with a letter

From Dev

Find letter in a String (charAt)

From Dev

sql find name with letter

From Dev

Using Scanner to find letter

From Dev

How to Have Drupal WebForm phone number input show a keypad on a mobile device

From Dev

Converting a letter to a digit for phone number in Python

From Dev

letter to number converter in phone key pad format

Related Related

  1. 1

    Find letter combination on phone keypad

  2. 2

    How do I find a combination of a letter a number in a VBA string?

  3. 3

    Android : TYPE_CLASS_PHONE keypad issue

  4. 4

    Creating JavaScript Phone Keypad with Alphabet for SMS

  5. 5

    Creating JavaScript Phone Keypad with Alphabet for SMS

  6. 6

    Combination of a letter using recursive

  7. 7

    Python: Every possible letter combination

  8. 8

    Batch to find a string of number&letter combination only in first 10 characters (in a txt file) per row and print the whole row

  9. 9

    Batch to find a string of number&letter combination only in first 10 characters (in a txt file) per row and print the whole row

  10. 10

    generate random letter and fixed number combination

  11. 11

    How to match letter combination and it's occurences

  12. 12

    regex to remove ANY number/letter combination?

  13. 13

    vim - Prefix number to 3 letter combination bdw

  14. 14

    Python: print possible letter combination of key size

  15. 15

    vim - Prefix number to 3 letter combination bdw

  16. 16

    regex to remove ANY number/letter combination?

  17. 17

    Map letter-number combination into command in vim

  18. 18

    How to find name of key for use in ~/.XCompose? (specifically keypad plus and minus)

  19. 19

    Mongoose find on field combination

  20. 20

    Find Random BitshiftRight Combination

  21. 21

    Find combination of groups and letters

  22. 22

    Ruby find combination

  23. 23

    Find a selector starting with a letter

  24. 24

    Find letter in a String (charAt)

  25. 25

    sql find name with letter

  26. 26

    Using Scanner to find letter

  27. 27

    How to Have Drupal WebForm phone number input show a keypad on a mobile device

  28. 28

    Converting a letter to a digit for phone number in Python

  29. 29

    letter to number converter in phone key pad format

HotTag

Archive