.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Collections >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Get numbers in the list in C#.net

Posted By:Narayanan       Posted Date: February 22, 2012    Points: 40    Category: Collections    URL: http://www.dotnetspark.com  

Today,we will discuss about the get numbers in the list in C#.net How many numbers in the number in C#.Net? Eg: ex: txtExtractNo -- 2 txtInput -- 20 txtresult -- 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 This is a task.How many 2's in the txtResult.I create a function for this result.that is called CompareText
 

Objective
1 TextBox  txtExtractNo
2 TextBox  txtInput
3 TextBox  txtresult

1 Button -- List
2 Button -- Result


ex: txtExtractNo -- 2
      txtInput        -- 20
      txtresult        -- 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
List -- Click List button you can see the txtresult Data.
Result -- Click Result button .You can see the Messagebox with counting of numbers(How many 2's in the txtresult box)

// write code here
Member Declaration

   public static int result;

        int chk;

Function:

 private int  CompareText(string fValue, string svalue)

        {



            string formHeading = fValue;



            string userSearch = svalue;



            string constring = string.Empty;



            string comstring = string.Empty;



            string[] formHeadingWords;



            string[] userSearchWords;

          



            formHeadingWords = System.Text.RegularExpressions.Regex.Split(formHeading, @"\W");



            userSearchWords = System.Text.RegularExpressions.Regex.Split(userSearch, @"\W");



            int cntFarray = formHeadingWords.Length;



            int cntSarray = userSearchWords.Length;



            if (cntSarray > cntFarray)

            {



                foreach (string _str in userSearchWords)

                {

                    int strlength = _str.Length;

                    if (strlength == 1)

                    {

                        if (formHeading.Contains(_str))

                        {

                            chk = 1;

                        }

                     }

                    else if (strlength  > 1 )

                    {

                        thechars = _str.ToCharArray();

                        for (int idx = 0; idx < thechars.Length; idx++)

                        {

                            if (formHeading.Contains(thechars[idx]))

                            {

                                chk = chk + 1;

                            }

                        }

                   }

                }



            }

            result = chk;



            return result;

        }



   private void button1_Click(object sender, EventArgs e)

        {



            for (int idx = 1; idx <= Convert.ToInt32(textBox1.Text); idx++)

            {

              if (str == null)

                {

                    str = Convert.ToString(idx);

                }

                else

                {

                    str = str  +  "," + Convert.ToString(idx);

                }

            }

            textBox3.Text = str;

        }

        private void button2_Click(object sender, EventArgs e)

        {

            int chkvalue = Convert.ToInt32(textBox2.Text);

            int  str =   CompareText(textBox2.Text, textBox3.Text);

          MessageBox.Show(Convert.ToString(str));

        }



        private void textBox1_TextChanged(object sender, EventArgs e)

        {

            str = null;

        }






Output is : 3..


Conclusion
   So you can get how many numbers  in the list.Thanks for reading this articles.any feedback :please contact this ID:irnaraayanan@yahoo.com




     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend