Lahiru Prasanna
Lahiru Prasanna

Reputation: 1092

How to type apostrophe character in android strings xml

If i try to do things like this, it doesn't work... (empty string or no resource type error)

<string name="make_sales_order">FAIRE L'ORDRE DE VENTE </string>

how to use apostrophe character in android string xml.any ideas?

Upvotes: 12

Views: 17858

Answers (4)

zetatlas
zetatlas

Reputation: 680

The curved apostrophe is a little more professional for user-facing messaging than the straight one mentioned above. The unicode for start and end curved apostrophes is 2018 and 2019. In Android strings.xml, you preface with a \u, u\2019

For example: The possessive word Bob's would be: <string>Bob\u2019s</string>

Here is a reference for punctuation UTF codes: https://symbl.cc/en/unicode/blocks/general-punctuation/

Upvotes: 1

Dipali Shah
Dipali Shah

Reputation: 3798

1. For Single Quote (')

You can use \' in your string resources.

or

You can enclose the string in double quotes. For example:

"This'll work" will simply become This'll work once parsed

2. For double quote (")

"message \"quote string 1\" and \"quote string 2\" end message"

3. To represent in views xml (eg layout.xml), you have to use HTML character entities (like ")

"message &quot;quoted string 1&quot; and &quot;quoted string 2&quot; end message"

Though Android Studio in particular will complain about hardcoded strings and tell you to use a string resource in layout files instead of course!

Upvotes: 25

user5908278
user5908278

Reputation:

Use \' in your string.xml

<string name="make_sales_order">FAIRE L\'ORDRE DE VENTE </string>

Upvotes: 8

Jinal Patel
Jinal Patel

Reputation: 709

<string name="make_sales_order">FAIRE L\&#39;ORDRE DE VENTE</string>

Upvotes: 1

Related Questions