Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A caution on Spotlight searches and ampersands Apps
While working on HTML files, I often use a special character, the 'em-dash' (—). In HTML code, an em-dash is made using a numerical code that begins with an ampersand (&):
—
I wanted to search for all my HTML files containing that code, but Spotlight wouldn't find them if I typed in the whole code. If I left off the initial ampersand (#8212), Spotlight would find the entries. It seems to me that Spotlight can only find ampersands in certain cases, but which ones those are, I don't know yet.

So if you're looking for coded HTML entities in your files, try searching without the ampersand.
    •    
  • Currently 2.50 / 5
  You rated: 4 / 5 (8 votes cast)
 
[8,706 views]  

A caution on Spotlight searches and ampersands | 10 comments | Create New Account
Click here to return to the 'A caution on Spotlight searches and ampersands' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A caution on Spotlight searches and ampersands
Authored by: ghay on Sep 25, '08 08:51:06AM

As a side note

–
—

both work in HTML, and would allow you to search for ndash or mdash in spotlight.



[ Reply to This | # ]
A caution on Spotlight searches and ampersands
Authored by: osxpounder on Sep 25, '08 09:02:25AM

I agree; that would be easier to deal with. Thanks for pointing that out for us. Those words are easier to remember than the numerical code.

Sadly, in my particular case, I can't use those codes -- I'm marking up XML, to be literal, but using whatever HTML markup the application allows. The application is one a coworker built in Flash a year or two ago.

Whether it's Flash's limitation or not, I don't know, but I can't use some HTML markup, including those. Sometimes testing shows that certain HTML markups aren't interpreted correctly, and I have to work around it.



[ Reply to This | # ]
A caution on Spotlight searches and ampersands
Authored by: Anonymous on Sep 25, '08 11:46:42AM

FYI: My wife's a highly talented Web designer, and she uses the numeric codes in preference to the mnemonic versions for a very good reason, which for the life of me I cannot remember just now.

It's partly to do with the mnemonics being a Microsoftism, and not fully ratified in the Web standards; yet they pass muster in the W3C's validator. But that's not the end of the story.



[ Reply to This | # ]
A caution on Spotlight searches and ampersands
Authored by: lar3ry on Sep 27, '08 08:37:28PM
OK, here's the scoop...

Unless your DTD allows for named entity codes (like —) then you have to use the numeric entities. Otherwise, they aren't defined.

XML only requires five named entities (in order to "escape" the special characters in XML). Those named entities are ' (apostrophe, or single quote), " (double-quote), & (ampersand), < (less than), and > (greater than). Those entities are "inherited" by all XML-based languages.

HTML and XHTML, on the other hand, have nearly 250 named entities defined. The names are easy to remember once you see their "description" in English (— is an em-dash, for example). You can see all those useful HTML/XHTML named entities in a handy list at Wikipedia: http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

When working with various XML or SGML-based markup languages, the numeric entities are universal. THAT is the reason why some people use numeric entities exclusively--they are guaranteed to work. The numbers in the entities refer to the 16-bit UNICODE value for the character.

[ Reply to This | # ]
Ampersands
Authored by: jediknil on Sep 25, '08 09:19:31AM

Have you tried "—"? It's possible Spotlight is "fixing" the constant for you, and any other time it sees a possible XML entity.



[ Reply to This | # ]
Ampersands
Authored by: osxpounder on Sep 25, '08 04:11:50PM

Thanks for that tip; I tried it, and Flash seems to be interpreting it correctly. At least, it looks right in Firefox and Safari right now.

Even though my markup works fine with the code in the hint, I'll use your suggestion, because "amp;" is familiar to me, so maybe next time I search I'll think to search for that.



[ Reply to This | # ]
A caution on Spotlight searches and ampersands
Authored by: noworryz on Sep 25, '08 01:49:16PM

The spotlight search in the upper right hand corner of the screen is limited to normal word searches. Instead, click on the desktop and type Command-F. Pull down the search entry menu defaulting to "Kind" and select "Other..." instead. Choose "Text content" from the resulting dialog box. Then enter the ampersand in the text box to the right.
The search result will be different and, I suspect, may fill your need.



[ Reply to This | # ]
A caution on Spotlight searches and ampersands
Authored by: osxpounder on Sep 25, '08 04:15:52PM

Sadly, no. Same results (lack of results). Originally I used the search field in the Finder toolbar rather than Cmd-F, but I hadn't tried the default Spotlight (Cmd-Space) search until I was testing before I submitted the hint.

Oddly, though, I just tried Cmd-Space to search for "—" right now, and it turned up just one hit (there should be at least 3), and it was in an email I sent *about this hint on this site*. So, Spotlight finds that text string if it's in a Mail message. Odd.



[ Reply to This | # ]
A caution on Spotlight searches and ampersands
Authored by: derrickbass on Sep 25, '08 11:05:49PM

This doesn't really address the problem at hand, but why not just write your HTML in UTF-8 and forget all these entities (well, except for &, <, and >)?



[ Reply to This | # ]
A caution on Spotlight searches and ampersands
Authored by: jhopper28 on Mar 09, '09 11:30:29AM

When I use Spotlight to search, it doesn't find any .HTML file contents. If I rename an .HTML file to use a .TXT extension, the contents are found. Is there a way to enable Spotlight to find contents in .HTML files?



[ Reply to This | # ]