Evaluating Even Number of Characters

tate

Well-known member
Joined
Nov 10, 2003
Messages
116
Im sure there has to be a simple way of doing this but I have spent hours pouring over web pages and books but cant get started in the right direction!

What I would like to do is evaluate a text box to determine if there is an even number of characters. I thought I could do use something like this;

IEEERemainder(txtField.Length, 2)

If the returned value was greater than 0 then apparently there would not be an even number of characters.

However the results were rather unpredictable.

Any suggestions would be greatly appreciated.
Tate
 
do you mean by even that it is dividable by 2? (english is not my native language)

if yes then use this

if (txtField.Length % 2)
// code for even
else
// code for not even


if i understood you wrong, then please tell me :)
 
Im not aware of any such syntax. What does the "%" character do? I cant find any reference to it in the Visual Studio help index.


Thanks for the reply.
 
The code given is C# - % is the modulus operator (it returns the remainder after dividing two numbers)

if you are using vb then there is a mod function

Code:
If txtField.Length Mod 2 = 0 then
even
else
odd
end if
 
Appears the Mod function returns the same thing as the IEEERemainder function.

Either will work fine now that I understand them better. Thanks for everyones input.


Tate
 
Back
Top