Click here to Skip to main content
Rate this: bad
good
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 | :laugh:
 
Can I do that, how? OR is there any better way to achieve this?
 

Thanks
Posted 6-Dec-09 22:00pm
nGrafix173
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Gihan Liyanage 332
1 Sergey Alexandrovich Kryukov 330
2 ClimerChinna 222
3 vikinghunter 168
4 OriginalGriff 166
0 Sergey Alexandrovich Kryukov 8,363
1 OriginalGriff 7,112
2 CPallini 2,598
3 Richard MacCutchan 2,025
4 Abhinav S 1,788


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 7 Dec 2009
Copyright © CodeProject, 1999-2014
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