Welcome :Guest

Congratulations!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

 Home >> Code Snippets >> Collections >> Post New Resource

# 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 userSearch = svalue;

string constring = string.Empty;

string comstring = string.Empty;

string[] userSearchWords;

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

int cntSarray = userSearchWords.Length;

if (cntSarray > cntFarray)

{

foreach (string _str in userSearchWords)

{

int strlength = _str.Length;

if (strlength == 1)

{

{

chk = 1;

}

}

else if (strlength  > 1 )

{

thechars = _str.ToCharArray();

for (int idx = 0; idx < thechars.Length; 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