In this example, I have demonstrate, how to match a string from a string Array. This is very simple, make a function, which will return bool variable if string is match from a string Array.
Here’s is a solution
Default.aspx
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Match a string from a string Array</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>
Match a string from a string Array</h2>
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
string[] Array = new string[] { "Saba Khan", "Awais Ahmed", "Mahwish Hasan", "Aamir Hasan" };
string Find = "Aamir Hasan";
Label1.Text += "<strong>Array</strong><br>";
foreach (string item in Array)
Label1.Text += item.ToString() + "<br>";
Label1.Text += "<strong>Find:</strong>" + Find.ToString() + "<br>";
Label1.Text += (Match(Array, Find)) ? ("Matched") : ("Not Matched");// return matched or not matched.
}
public static bool Match(string[] arr, string Item)
{
return arr.Contains(Item);
}
Default.aspx.vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim Array As String() = New String() {"Saba Khan", "Awais Ahmed", "Mahwish Hasan", "Aamir Hasan"}
Dim Find As String = "Aamir Hasan"
Label1.Text += "<strong>Array</strong><br>"
For Each item As String In Array
Label1.Text += item.ToString() + "<br>"
Next
Label1.Text += "<strong>Find:</strong>" + Find.ToString() + "<br>"
Label1.Text += If((Match(Array, Find)), ("Matched"), ("Not Matched"))
' return matched or not matched.
End Sub
Public Shared Function Match(ByVal arr As String(), ByVal Item As String) As Boolean
Return arr.Contains(Item)
End Function
Output

Download
MatchString.zip (984.00 bytes)
Live demo