Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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???

tHe pHrEaKy
Posted

(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

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted
(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.

tHe pHrEaKy
Posted

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.

Nothing is as illusive as 'the last bug'.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...