CheapApples12
CheapApples12

Reputation: 97

String matching from a list

I am making a web browser and I am stuck on this one thing. I want the addres bar to act as an address bar and a search bar. First I tried seeing if querying the search bar with if adrBarTextBox.text.endswith(".com") but immediately realized that not every domain ended with .com.

The code I am currently using (and are stuck with) is:

// Populate List.
var list = new List<string>();
list.Add(Properties.Settings.Default.suffix);

(Properties.Settings.Default.suffix is a list of every domain suffix currently available)

// Search for this element.
if (adrBarTextBox.Text.Contains(list.something????))
{
    // Do something (I have this part all set up)
}

The part i am having trouble with is

if (adrBarTextBox.Text.Contains(list.

I know it doesn't make sense but thats why i am asking. I have sat here thinking of a new way for hours and I am lost. I know that .Text.Contains(list) doesn't make sense and that's what I am stuck with.

I know the question is a bit noobish and there is probably some simple easy was staring me right in the face but hey. We all have to learn from somewhere.

Upvotes: 3

Views: 66

Answers (2)

Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104741

Use Uri.IsWellFormedUriString to determine if the input string is a valid URL.

If you want to match a string with words against another list of words, use

myList.Any(item => input.Contains(item));

Upvotes: 1

M. Nasir Javaid
M. Nasir Javaid

Reputation: 5990

You may need this

if (list.Any(x => adrBarTextBox.Text.Contains(x)))
{
   //...
}

Upvotes: 1

Related Questions