phreaky Posted May 27, 2005 Posted May 27, 2005 How can I compare two numeric string to see which one is bigger?, I mean, I have two strings submited by textboxes....I try to compare if sting a (14) is bigger than string B (9), but it keeps saying me B is bigger (if I just compare textbox1 < textbox2). How can I compare two strings by its numeric values? I tried to use convert.toint16, but it says I give the string in bad format. How can I compare those??? Quote tHe pHrEaKy
techmanbd Posted May 27, 2005 Posted May 27, 2005 (14) - is this what your string looks like? if so you need to take out the parenthesis. Woulkd help if we saw the code for what you are trying to do Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
phreaky Posted May 27, 2005 Author Posted May 27, 2005 (14) - is this what your string looks like? if so you need to take out the parenthesis. Woulkd help if we saw the code for what you are trying to do No, the parenthesis were there ONLY to make tell an example of the string, my string is just a number. Quote tHe pHrEaKy
thenerd Posted May 28, 2005 Posted May 28, 2005 Well, the textbox.text property will get you the string. And then you use integer.parse to make it into a number. Quote
Wile Posted May 28, 2005 Posted May 28, 2005 If you do a check textbox1.Text > textbox2.Text it won't do a numeric '>' check, but a string check. I dont know how they work, but it could be that the starting character would be leading (like you get 1, 10, 11 .. 19, 2, 20, 21 .. 29, 3, 30, ... in some sort orders) That makes 1000 smaller than 9 but still bigger than 10. If you want to make sure a numeric check is done, you must first convert all texts to numbers. Use int.parse(textbox.text) to convert the text to a number. For floating points you can use double.parse. Quote Nothing is as illusive as 'the last bug'.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.