in

 

Jimmy Bogard

Assistant to the assistant to the regional manager

When a space isn't a space

I ran into a scenario recently where this test failed:

[Test]
public void You_have_to_be_kidding_me()
{
    string a = "You have to be kidding me       ";
    string b = "You have to be kidding me       ";

    a.ShouldEqual(b);
}

It took me quite a while to determine the problem, as it originally came from a column in the database with natural keys.

When a test like this fails, it's time to call it a day.  Any guesses as to the problem?

Published Jun 26 2008, 07:15 AM by bogardj
Filed under:

Comments

 

Guesser said:

Tab vs space?

June 26, 2008 8:42 AM
 

Peter Ritchie said:

No-break space?  I love that one...  use ALT-0160 (where 0160 are the numbers typed on the numeric keypad) to generated a no-break space.

June 26, 2008 8:59 AM
 

Matt said:

Natural keys?  ;)

June 26, 2008 9:24 AM
 

Jason L said:

Along the lines of what Peter Ritchie said, I would take a look at each char in the string and see where they differ.

Maybe a :

for (int i = 0; i < a.Length; i++)

 Assert.AreEqual(aIdea, bIdea);

You could also output each chars int value and look it up on the ascii table (if they are ascii strings).

and see where they differ.

June 26, 2008 9:33 AM
 

terry said:

ran into something similar, but instead of spaces it was a hyphen. different encodings from different sources yield unhappy results. here's a snippet from our codebase:

     #IE blows up on the '`' character. Asciify won't recognize it as a non-ascii character.

     #Some of these characters look similar, but one is utf-8 and the other is ascii. If

     #you change the encoding of this file (it's utf-8), I'm pretty sure you just broke the build. don't do that

     replaces = {'`' => '\'', '–' => '-', '’' => '\''}

yeah, that's right, it looks like "map - to -"

...

oh, and my guess is you've got whitespace in an encoding that doesn't match the regular \w

June 26, 2008 9:47 AM
 

Bryan Reynolds said:

Finally, real proof of magic! I have waited so long for this.

June 26, 2008 10:35 AM
 

bogardj said:

@Peter

DING DING DING DING

You got it.

I love Unicode...and I have zero idea how that value got in there in the first place.

June 26, 2008 7:39 PM
 

James Gregory said:

I had a similar problem recently where I was stripping newlines from some imported data, except the data had a combination of newlines and vertical tabs! Fun times.

June 27, 2008 3:59 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About bogardj

I'm a senior consultant with Headspring Systems in Austin, TX. My focus is using .NET technologies together with Agile methodologies. Back in 2005, I drank the Agile punch and haven't looked at a waterfall the same since.
Copyright Los Techies 2007. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems