From 3aba19a6c0f2b4473e82330870e7951f57746456 Mon Sep 17 00:00:00 2001 From: Andrew Solovay Date: Thu, 2 Apr 2015 15:10:51 -0700 Subject: [PATCH] Docs: Correcting section on how to escape quotes in strings. The behavior for single and double-quotes is different--I expanded this section to note how they differ. (New version of a Gerrit CL I abandoned because of a commit mess-up.) See first comment for doc stage location. bug: 19959941 Change-Id: I417546a473f0ebe76a6e4102b87883a85365ac26 --- .../guide/topics/resources/string-resource.jd | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/docs/html/guide/topics/resources/string-resource.jd b/docs/html/guide/topics/resources/string-resource.jd index cbfa82e7dafdd..743e69233645b 100644 --- a/docs/html/guide/topics/resources/string-resource.jd +++ b/docs/html/guide/topics/resources/string-resource.jd @@ -401,19 +401,35 @@ android.content.res.Resources#getQuantityString(int,int) getQuantityString}.

format and style your string resources.

-

Escaping apostrophes and quotes

+

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:

+

+ If you have an apostrophe (') in your string, you must either + escape it with a backslash (\') or enclose the string in + double-quotes (""). For example, here are some strings 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="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&apos;t work</string>
+    <!-- Causes a compile error -->
 
+

+ If you have a double-quote in your string, you must escape it + (\"). Surrounding the string with single-quotes does + not work. +

+ +
+<string name="good_example">This is a \"good string\".</string>
+<string name="bad_example">This is a "bad string".</string>
+    <!-- Quotes are stripped; displays as: This is a bad string. -->
+<string name="bad_example_2">'This is another "bad string".'</string>
+    <!-- Causes a compile error -->
+

Formatting strings