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


Top 5 Contributors of the Month
david stephan

Post New Resource Bookmark and Share   

Logic solution in C#.net

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

In this Article,we discuss about the Logic solution in C#.net. How many numbers in the number?
 

I have 3 textBox and 2 Button in my form.

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)

Here is the Coding
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.



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Here

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