Click here to Skip to main content
13,050,450 members (81,127 online)
Rate this:
Please Sign up or sign in to vote.
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?

Posted 6-Dec-09 22:00pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 7 Dec 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100