aspx Tutorial

.NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services, .NET articles, Sharepoint 2010, visual studio 2010,Aamir Hasan,IT
Advertise Here

Advertize

wwwSW
Posted by Aamir Hasan   on Tuesday, November 2, 2010 Total Views:  

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

Protected by Copyscape Online Plagiarism Tool

Comments (3) -

ez loan
ez loan United States
1/5/2011 8:32:52 PM #

In the highest civilization, the book is still the highest delight. He who has once known its satisfactions is provided with a resource against calamity.

mbt shoes
mbt shoes Libya
3/28/2011 9:43:08 PM #

Time is changed  ,distance is changed ,but our friendship is lasting forever !

fafafa
fafafa Slovenia
4/23/2012 3:03:58 AM #

http://www.christianlouboutinukk.org   christian louboutin
http://www.tiffanyuks.org   tiffany uk
http://www.gucciukbeltuk.org   gucci belt
http://www.frsaclouisvuittonsac.com   louis vuitton sac
http://www.chanelukoutletuks.org   chanel outlet
http://www.burberryukoutletuk.org   burberry
http://www.poloralphlaurenuko.org   ralph lauren uk

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5