I'm speechless about this piece of code.
-
I've just read an article that included this little gem
://it checks it contains 11 char (dd/MMM/yyyy) if (Convert.ToInt16(chkdate.Length.ToString()) != 11) { //if it does not have 11 char then it will return false return false; }
I really don't know where to start (and yes, chkdate is a string).
Deja View - the feeling that you've seen this post before.
-
I've just read an article that included this little gem
://it checks it contains 11 char (dd/MMM/yyyy) if (Convert.ToInt16(chkdate.Length.ToString()) != 11) { //if it does not have 11 char then it will return false return false; }
I really don't know where to start (and yes, chkdate is a string).
Deja View - the feeling that you've seen this post before.
Odd that it does "actually" check for 11 characters. I wonder what the code looks like that ensures the "dd/MMM/yyyy" format. There's likely a gem or two in that as well. :)
Chris Meech I am Canadian. [heard in a local bar] Donate to help Conquer Cancer[^]
-
Odd that it does "actually" check for 11 characters. I wonder what the code looks like that ensures the "dd/MMM/yyyy" format. There's likely a gem or two in that as well. :)
Chris Meech I am Canadian. [heard in a local bar] Donate to help Conquer Cancer[^]
-
I've just read an article that included this little gem
://it checks it contains 11 char (dd/MMM/yyyy) if (Convert.ToInt16(chkdate.Length.ToString()) != 11) { //if it does not have 11 char then it will return false return false; }
I really don't know where to start (and yes, chkdate is a string).
Deja View - the feeling that you've seen this post before.
It worries me that we are spiralling into some kind of recursive software hellhole:
void WritePoorCode()
{
bool stuck = true;if (stuck) { GetHelpFromAnotherMuppet(); }
}
void GetHelpFromAnotherMuppet()
{
WritePoorCode();
} -
Great. It doesn't validate a thing. :)
Chris Meech I am Canadian. [heard in a local bar] Donate to help Conquer Cancer[^]
-
It worries me that we are spiralling into some kind of recursive software hellhole:
void WritePoorCode()
{
bool stuck = true;if (stuck) { GetHelpFromAnotherMuppet(); }
}
void GetHelpFromAnotherMuppet()
{
WritePoorCode();
}:cool:
Chris Meech I am Canadian. [heard in a local bar] Donate to help Conquer Cancer[^]
-
It worries me that we are spiralling into some kind of recursive software hellhole:
void WritePoorCode()
{
bool stuck = true;if (stuck) { GetHelpFromAnotherMuppet(); }
}
void GetHelpFromAnotherMuppet()
{
WritePoorCode();
}:laugh:Kermit the coder.
Deja View - the feeling that you've seen this post before.
-
:cool:
Chris Meech I am Canadian. [heard in a local bar] Donate to help Conquer Cancer[^]
Add tail calls, and it will run forever :)
xacc.ide
IronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach." -
I've just read an article that included this little gem
://it checks it contains 11 char (dd/MMM/yyyy) if (Convert.ToInt16(chkdate.Length.ToString()) != 11) { //if it does not have 11 char then it will return false return false; }
I really don't know where to start (and yes, chkdate is a string).
Deja View - the feeling that you've seen this post before.
Pete O`Hanlon wrote:
Convert.ToInt16(chkdate.Length.ToString()) != 11
why do you rely on an implicit Int16-to-Int32 conversion? I would recommend an explicit cast to make things more clear. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
-
Pete O`Hanlon wrote:
Convert.ToInt16(chkdate.Length.ToString()) != 11
why do you rely on an implicit Int16-to-Int32 conversion? I would recommend an explicit cast to make things more clear. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
That's right. You can't have enough casting and converting going on.
Deja View - the feeling that you've seen this post before.
-
Pete O`Hanlon wrote:
Convert.ToInt16(chkdate.Length.ToString()) != 11
why do you rely on an implicit Int16-to-Int32 conversion? I would recommend an explicit cast to make things more clear. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
Rediculous .. you need to convert both to decimal to guarentee precision and get rid of that pesky implicit conversion ...
if(Convert.ToDecimal(Convert.ToInt16(chkdate.Length.ToString())) != Convert.ToDecimal("11")) {
doNoRealValidationCheck_NeverLearnRegex();
}
I'm largely language agnostic
After a while they all bug me :doh:
-
I've just read an article that included this little gem
://it checks it contains 11 char (dd/MMM/yyyy) if (Convert.ToInt16(chkdate.Length.ToString()) != 11) { //if it does not have 11 char then it will return false return false; }
I really don't know where to start (and yes, chkdate is a string).
Deja View - the feeling that you've seen this post before.
He could've written:
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[0]) != new String("1").ToCharArray()[0])
{
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[1]) != new String("1").ToCharArray()[0])
{
return false;
}
}xacc.ide
IronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach." -
He could've written:
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[0]) != new String("1").ToCharArray()[0])
{
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[1]) != new String("1").ToCharArray()[0])
{
return false;
}
}xacc.ide
IronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."Except you forgot to convert the char types to some int type to ensure it would be a numeric comparison. :rolleyes: :)
Chris Meech I am Canadian. [heard in a local bar] Donate to help Conquer Cancer[^]
-
He could've written:
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[0]) != new String("1").ToCharArray()[0])
{
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[1]) != new String("1").ToCharArray()[0])
{
return false;
}
}xacc.ide
IronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."leppie wrote:
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[0]) != new String("1").ToCharArray()[0]){ if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[1]) != new String("1").ToCharArray()[0]) { return false; }}
Not so fast, your code does not work while his does. ;P [Hint] Your code will not return false for strings of length 1, 10, 101, etc.
-
I've just read an article that included this little gem
://it checks it contains 11 char (dd/MMM/yyyy) if (Convert.ToInt16(chkdate.Length.ToString()) != 11) { //if it does not have 11 char then it will return false return false; }
I really don't know where to start (and yes, chkdate is a string).
Deja View - the feeling that you've seen this post before.
-
It's dead! =\
ROFLOLMFAO
-
Pete O`Hanlon wrote:
Convert.ToInt16(chkdate.Length.ToString()) != 11
why do you rely on an implicit Int16-to-Int32 conversion? I would recommend an explicit cast to make things more clear. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
I think this improves the code a lot… Extra precisions and conversions to make sure we're getting exactly what we want. :) ((Decimal)Convert.ToDecimal(chkdate.Length.ToString()) != (Decimal)Convert.ToDecimal(((Decimal)(11.0000000000000000000000000000)).ToString())).ToString() == Boolean.TrueString; The optimizing JITter is going to have fun with this one…
ROFLOLMFAO
-
I think this improves the code a lot… Extra precisions and conversions to make sure we're getting exactly what we want. :) ((Decimal)Convert.ToDecimal(chkdate.Length.ToString()) != (Decimal)Convert.ToDecimal(((Decimal)(11.0000000000000000000000000000)).ToString())).ToString() == Boolean.TrueString; The optimizing JITter is going to have fun with this one…
ROFLOLMFAO
You left out the string.compare call with the ignore case option, and specifying the CultureInfo on the ToString calls. :doh:
This blanket smells like ham
-
leppie wrote:
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[0]) != new String("1").ToCharArray()[0]){ if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[1]) != new String("1").ToCharArray()[0]) { return false; }}
Not so fast, your code does not work while his does. ;P [Hint] Your code will not return false for strings of length 1, 10, 101, etc.
Of course not ! :) Thats an exercise for the next poor soul that works on the code :p
xacc.ide
IronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach." -
I've just read an article that included this little gem
://it checks it contains 11 char (dd/MMM/yyyy) if (Convert.ToInt16(chkdate.Length.ToString()) != 11) { //if it does not have 11 char then it will return false return false; }
I really don't know where to start (and yes, chkdate is a string).
Deja View - the feeling that you've seen this post before.
Is this what they call optimized code? :confused:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.