I have declared a long string in string.xml
of an application.
Declared like this
PLEASE READ THESE TERMS
Use this regex (?<!\\)'
for searching an unescaped apostrophe.
It finds an apostrophe that not preceded by a backslash.
post your complete string. Though, my guess is there is an apostrophe (') character in your string. replace it with (\') and it will fix the issue. for example,
//strings.xml
<string name="terms">
Hey Mr. Android, are you stuck? Here, I\'ll clear a path for you.
</string>
Ref:
http://www.mrexcel.com/forum/showthread.php?t=195353
https://code.google.com/archive/p/replicaisland/issues/48
I use hebrew(RTL language) in strings.xml. I have manually searched the string.xml for this char: ' than I added the escape char \ infront of it (now it looks like \' ) and still got the same error!
I searched again for the char ' and I replaced the char ' with \'(eng writing) , since it shows a right to left it looks like that '\ in the strings.xml !!
Problem solved.
The best answer of simply escaping the '
with \'
works but I do not like the solution because when using replace all with '
to \'
, it only works once. The second time you'll be left with \\'
.
Therefore, use: \u0027
.
https://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling
Escaping apostrophes and quotes
If you have an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the other type of enclosing quotes. For example, here are some stings that do and don't work:
<string name="good_example">"This'll work"</string>
<string name="good_example_2">This\'ll also work</string>
<string name="bad_example">This doesn't work</string>
<string name="bad_example_2">XML encodings don't work</string>
You may be able to use unicode equivalent both apostrophe and other characters which are not supported in xml string. Apostrophe's equivalent is "\u0027" .