I remember once being told a long time ago that someone famous said that the littlest things mean the most. They were talking about people and how those small gestures and actions that we do for one another seem like nothing, but in fact mean everything. What do I mean? Well, squeezing someone’s hand a certain way…or a look across a room. Or even, putting an ‘x’ at the end of a message; that kind of thing.
I was thinking about that this week when I had a small problem where I wasn’t able to match against this string that appeared in a Word document:
I was using Microsoft’s Open Office XML (OOXML) to strip out the cells from a series of tables and then convert them into a list of strings. How I did that isn’t important, but this is what I could see when I inspected the object in VS 2012:
And this is how I was trying to match against it:
/// Perform a case insensitive search of the list for a given search term
/// <param name="searchTerm">Term to search for</param>
/// <param name="startFrom">Index from where to begin looking</param>
/// <param name="elements">List of elements to search in</param>
private int GetIndexOf(string searchTerm, int startFrom, List<String> elements)
Debug.Assert(startFrom >= 0);
Debug.Assert(elements != null);
int result = -1;
CompareInfo compare = CultureInfo.CurrentCulture.CompareInfo;
for (index = startFrom; index < elements.Count; index++)
result = compare.IndexOf(elements[index], searchTerm, CompareOptions.IgnoreCase);
if (result == 0)
// Did not find the string
In case you’re wondering why I didn’t just use something like
IndexOf on the
IEnumerable, it was important that I had the ability to search without considering the case: see line 19.
Then, for some reason, when I would do something like:
int result = GetIndexOf("Manager's name", 0, elements)
I kept getting a return value of
-1 meaning it wasn’t finding an exact match. Humph.
I also tried things like:
bool j = elements.Any(c => c.Equals("Manager's name"));
int k = elements.IndexOf("Manager\u0027s name");
int l = elements.FindIndex(c => c.Equals("Manager''s name"));
and all combinations thereof. What made it all the more interesting was there are only two keys on my keyboard that look remotely like the apostrophe. Here’s one of them (the only one that really looks like it):
Humph ^ 2.
Before continuing, take a few minutes to think about what might have been the cause of the problem.
I hate giving up but usually when this happens I leave it for a while and come back to it. I guess it’s a count to ten kind of thing when someone is angry, though of course, I’m not! In fact, I love this type of thing and this work generally because for me, it’s like a huge puzzle that I just have to crack.
This time though I asked a friend whilst I moved onto something else and after a while, he realised what the problem was. Let me show you what this text looks like when you paste it into Notepad++.
Can you hear me groaning? Clearly, not all apostrophes are made the same.
The culprit was Word and in particular, a feature which means it replaces any quotes with smart ones, though to be honest, it didn’t feel too smart at the time. The reason I didn’t notice this is that the change from what you type on the keyboard to the other unicode character is lightning fast. So much so, you don’t even notice it. Here they are for completeness:
' = 27
’ = E28099
To fix it (should you want to), this is what you need to do in the options of Word:
In summary, be careful when searching for quotes where Microsoft Word is involved because you never know when it might want to act in a smart way.
Obviously, then, this post exists to try and help someone else out should they run into this kind of issue, but there is another reason.
Apostrophes…especially the little ones…mean everything.
Written by Stephen Moon
email: stephen at logicalmoon.com