Click here to Skip to main content
15,880,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guyz,

I wrote a tiny programme in VB.NET using VS.NET 2008 to sort numbers.

I take the input of numbers separated by commas from TextBox1.text, play some algorithm then by clicking a button, display the sorted values in TextBox2.text.

NOW i want to restrict the numbers to be only 20 positions (eg. 32,1,6,32,12,21,21,54,675,8,4,3,2,9,0,21,21,21,43,744) in the TextBox1.text and so i thought of counting the commas :laugh:

Can I do that, how? OR is there any better way to achieve this?


Thanks
Posted

No need to count the commas.
Use Textbox1.Text.Split(',').Length. It gives you the count of the numbers added in the textbox separated by comma.
 
Share this answer
 
You could do it the reqular expression way:
Dim valid AS Boolean = Regex.IsMatch(TextBox1.Text, "^(,?\d+){0,20}$")

This would also validate the input, anything other than numbers or commas would return false.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900