Click here to Skip to main content
15,913,854 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralMore on string comparison Pin
oggenok6424-Feb-11 18:42
oggenok6424-Feb-11 18:42 
JokeRe: More on string comparison Pin
Bernhard Hiller24-Feb-11 21:15
Bernhard Hiller24-Feb-11 21:15 
GeneralRe: More on string comparison Pin
_Erik_24-Feb-11 23:55
_Erik_24-Feb-11 23:55 
GeneralRe: More on string comparison Pin
musefan25-Feb-11 2:39
musefan25-Feb-11 2:39 
GeneralRe: More on string comparison Pin
Samuel Cragg25-Feb-11 3:52
Samuel Cragg25-Feb-11 3:52 
GeneralRe: More on string comparison Pin
musefan25-Feb-11 4:02
musefan25-Feb-11 4:02 
GeneralRe: More on string comparison Pin
Samuel Cragg25-Feb-11 5:09
Samuel Cragg25-Feb-11 5:09 
GeneralRe: More on string comparison Pin
musefan25-Feb-11 5:21
musefan25-Feb-11 5:21 
But the whole point in the trim (IMO) is to test that a complete whitespace string is not confused with meaningful data. Imagine if the string was fetched using my sample method, and the call to get the data in there returns a tab separated list - this function may always end in a tab even when no data has been added. so the resulting value could be "\t" in which case it should be ignored just like "" would be.

Your length test doesn't work in this case because a string of data and whitespace would equal the same. Consider the following possible string values and what you want to test for invalid...

string s = "";//empty and want to handle (length is 0 so fine)
string s = "\t";//as good as empty and want to handle (length is 1 so problem here)
string s = @"data 1\tdata 2\t";//some useful data and this will not be 'caught' by the trim test

Illogical thoughts make me ill

GeneralRe: More on string comparison Pin
Samuel Cragg25-Feb-11 5:40
Samuel Cragg25-Feb-11 5:40 
GeneralRe: More on string comparison Pin
musefan25-Feb-11 6:00
musefan25-Feb-11 6:00 
GeneralRe: More on string comparison Pin
oggenok6425-Feb-11 21:30
oggenok6425-Feb-11 21:30 
GeneralRe: More on string comparison [modified] Pin
musefan28-Feb-11 23:56
musefan28-Feb-11 23:56 
GeneralComparing objects? SIMPLE! Pin
TorstenH.24-Feb-11 3:32
TorstenH.24-Feb-11 3:32 
GeneralRe: Comparing objects? SIMPLE! Pin
_Erik_24-Feb-11 5:41
_Erik_24-Feb-11 5:41 
GeneralHow not to string a date Pin
PIEBALDconsult24-Feb-11 2:18
mvePIEBALDconsult24-Feb-11 2:18 
GeneralRe: How not to string a date Pin
musefan25-Feb-11 2:51
musefan25-Feb-11 2:51 
Ranti asked to explain this code, but i think i prefer a mental hospital . not a single description about what he done Pin
kdgupta8723-Feb-11 10:54
kdgupta8723-Feb-11 10:54 
GeneralRe: i asked to explain this code, but i think i prefer a mental hospital . not a single description about what he done Pin
AspDotNetDev23-Feb-11 11:02
protectorAspDotNetDev23-Feb-11 11:02 
GeneralRe: i asked to explain this code, but i think i prefer a mental hospital . not a single description about what he done Pin
kdgupta8723-Feb-11 11:30
kdgupta8723-Feb-11 11:30 
GeneralRe: i asked to explain this code, but i think i prefer a mental hospital . not a single description about what he done Pin
Chris Meech24-Feb-11 5:16
Chris Meech24-Feb-11 5:16 
GeneralRe: i asked to explain this code, but i think i prefer a mental hospital . not a single description about what he done Pin
Asday4-Mar-11 0:21
Asday4-Mar-11 0:21 
GeneralRe: i asked to explain this code, but i think i prefer a mental hospital . not a single description about what he done Pin
RobCroll23-Feb-11 16:35
RobCroll23-Feb-11 16:35 
GeneralRe: i asked to explain this code, but i think i prefer a mental hospital . not a single description about what he done Pin
kdgupta8723-Feb-11 19:00
kdgupta8723-Feb-11 19:00 
GeneralRe: i asked to explain this code, but i think i prefer a mental hospital . not a single description about what he done Pin
_Erik_24-Feb-11 5:28
_Erik_24-Feb-11 5:28 
GeneralRe: i asked to explain this code, but i think i prefer a mental hospital . not a single description about what he done Pin
phil.o24-Feb-11 5:43
professionalphil.o24-Feb-11 5:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.