Apostrophe not preceded by \

Frank Schnabel picture Frank Schnabel · Mar 29, 2013 · Viewed 80.9k times · Source

I have a string defined in an android application:

<string name="search_occurs">'{string}' occurs {times}</string>

This gives the error: Apostrophe not preceded by \ (in '{string}' occurs {times})

I've tried a number of things to fix this:

<string name="search_occurs">\'{string}\' occurs {times}</string>
<string name="search_occurs">&apos;{string}&apos; occurs {times}</string>
<string name="search_occurs"><![CDATA['{string}' occurs {times}]]></string>
<string name="search_occurs"><![CDATA[\'{string}\' occurs {times}]]></string>

I'm not able to get rid of the error. What am I missing?

Answer

John Boker picture John Boker · Mar 29, 2013

these should both work according to http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling:

<string name="search_occurs">\'{string}\' occurs {times}</string>
<string name="search_occurs">"'{string}' occurs {times}"</string>