I am working on windows application. My requirement is in my application I am retrieving text files and displaying the contents of text files in text box, but here i want to display text files which contains only numeric data. Where as in my application it will display numeric data as well as alphabets. How can i check text box does it contains numeric data or alphabets?
Finding Characters in a TextBox
Collapse
X
-
I'm a fan of the double.TryParse method myself... it doesn't have the overhead of a try/catch.
example...
Note, you don't necessarily have to have the if statement there... only if you want to tell if the conversion was successful. Hope that helps.Code:string sPi = "3.14159"; double dPi; if (double.TryParse(sPi, out dPi)) { // success } else { // failure }Comment
-
Instead of everyhing else you just need to use regular expressions.... in checking whether the text fetched from the file contains only numbers...
Code:Regex reg=new Regex("[0-9]*"); if(reg.IsMatch("fetched Data") { //display in textbox }Comment
Comment