Quoted strings

Description

We can use Quoted strings in Android string resource file.

Example

The quoted strings need to be either escaped or placed in alternate quotes.

The following XML string resource file needs to be in the /res/values subdirectory.


<resources>
    <string name="simple_string">simple string</string>
    <string name="quoted_string">"quoted 'xyz' string"</string>
    <string name="double_quoted_string">\"double quotes\"</string>
</resources>

The following java code shows how to use the resource file above.


/*from w  w  w.  j  ava 2s .  c  o  m*/
String simpleString = activity.getString(R.string.simple_string);
textView.setText(simpleString);

String quotedString = activity.getString(R.string.quoted_string);
textView.setText(quotedString);

String doubleQuotedString = activity.getString(R.string.double_quoted_string);
textView.setText(doubleQuotedString);

Note

From the code above we can see that there are two ways to add quotations to a string.





















Home »
  Android »
    Android Basics »




Hello Android
Resources
Activity
Calendar
Camera
Contact
Content Provider
Database
Hardware
Intent
Location
Media
Network
Notification
Preference
Sensor
Service
SMS