Android XML Editor removes Unicode Escapes - android

Hi i have unicode escapes in my xml files like that
android:text=""
but after hitting strg+shift+f for formatting it is replaced by
android:text=""
can i do anything about that?

For java recommended is \uF100 instead of  - this is not displayed even in my browser if not as "code" on fileinfo. Moreover, onfileino they posted:
U+F100 is not a valid unicode character.
But back to question - are you sure your file is utf-8 and project is also?

Related

Apostrophe converting to question mark in textview

I am parsing some external XML into an object and displaying this inside a textview.
Apostrophe's/single quotes are being converted to these silly question mark symbols.
Nothing i've found is working - i've tried using replaceall and escaping it with \', it doesn't give me the desired result.
I've tried setting the textview using:
tv.setText(Html.fromHtml(news_item.getTitle()));
It doesn't seem to work, I can't find any other solutions to this one, your ideas appreciated.
Try this:
tv.setText(news_item.getTitle().replaceAll("\u2019", "'"));
For other Unicode characters, please see this link.
Found it!
The mark you are looking for is called RIGHT SINGLE QUOTATION MARK with a unicode code of U+2019. This particular mark should be replaced via:
String.replace("’", "’");
for proper display.
If that doesn't work, you should do a substitution from that mark to a apostrophe via:
String.replace("’", "'");
or directly:
String.replace("’", "'");
to make sure the display actually displays it.
Close up of the difference between right single quotation mark vs apostrophe: ’ vs '
The documented solution will work, but it is not the right way of fixing this, as the root cause of the problem is encoding. In your case, the source's (XML document) encoding is most likely UTF-8 or some other multi-byte encoding. Your parser or consumer of the data is most likely ISO-8859-1 or ASCII. These characters (right/left apostrophes) are not part of that character set. Therefore, the correct solution is to change the encoding of your parser/processor/consumer to UTF-8.
If this is not the case, then it is probably the opposite. You have a process that writes down characters in UTF-8, but the XML's encoding is not compatible (i.e. ISO-8859-1).
Remember this: ALL characters in ISO-8859-1 are mapped in UTF-8, but not the other way around. So going from ISO-8859-1 to UTF-8 is not a problem. The problem is when you have to make the round trip to ISO-8859-1 to UTF-8. When converting UTF-8 characters, those characters NOT in the ISO character set, will show up funny on your display; either as question marks or "’

How can I put utf-16 characters in Android string resource?

I want to use Emojis in my app's strings. All strings reside, of course, in strings.xml
The problem is that not all Emojis are 16 bit friendly. Some Emojis can be represented as "normal" 16 bit hex: '\u26FF' but some are 32 bit hexes (UTF-16), usually represented as: '\x1F600'. I have no problem dealing with those inside the app, in code. But the strings.xml resource file is UTF8 encoded, and does not deal properly with non 16 bit escape chars.
I tried using '\x1F600' - because I saw that '\u26FF' works just fine. But it seems not to devour the 'x' escape char. Nor did it like the regexp notation '\x{1F600}'
So I ended up using a string placeholder '%1$s' and filling in the Emoji in code like this:
// greeting_3 is defined as: "hello there %1$s!"
String s = context.getString(R.string.greeting_3, "😜");
// OR:
String s = context.getString(R.string.greeting_3, new String(Character.toChars(0x1F61C)));
This is not a very elegant solution... is there a proper way to put 32 bit UTF-8 chars in strings.xml ?
But the strings.xml resource file is UTF8
If it's UTF-8 encoded, you can put your emojis directly. But then you risk that your editor or another piece of software destroys them.
If you are putting them in XML, you can try using XML entities: 😀, I'm not sure how well Android supports them though.
You can also use surrogate pairs: convert the emoji to UTF-16 and use standard \u escape. You can for example check out this page, it even tells you how to create a string litaral in Java: http://www.fileformat.info/info/unicode/char/1F600/index.htm
😜 → U+1F600 → "\uD83D\uDE00"
The easiest way it just copying and pasting the emoji, it works from Android Studio 3.0 and newer
Add the resource like follows:
<string name="string_title">This is a emoji example <U+1F642></string>
In Android Studio 3.0 you can copy and paste an emoji:
And here how it looks:

What is character 0x1f?

I've just imported a chunk of text into a string element for a book app and I'm getting this error : An invalid XML character (Unicode:0x1f) was found in the element content of this document.
I looked it up here http://lwp.interglacial.com/appf_01.htm and the description says US (removing underlining doesnt seem to work).
What is this character so I can remove it if possible.
I'm very new to android so simple answers please :)
0x1f is a Unit Separator, an archaic way to separate fields in a text (Like , or Tab in CSV).
It is indeed not a valid text character in XML 1.0 (but allowed in XML 1.1). In a UTF-8 input string, you can also safely replace the byte 0x1f with 0x09(Tab) to work around the problem. Alternatively, declare the document as XML 1.1 and use an XML 1.1 parser.
US means "Unit separator". This is an invisible character, so you should open your text file with some text editor that can show the invisible characters and remove them. I think that probably Notepad++ will give you this functionality:
http://notepad-plus-plus.org/
Use Nodepad++ you will find the "Unit separator".
Like the picture:

How to put Hebrew character in Android JAVA file?

For Android Platform:
I need to put Hebrew Character ₪ and some more like אורנג in string to check with the incoming data in java file. When I put this character It shows an error like "Some characters can not be mapped using "Cp1252" character encoding. Either change the encoding or remove the characters which are not supported by the "Cp1252" character encoding". These values are coming from SQLite database. Please see the attached snap. How can I solve this? Kindly give me some useful suggestions. Looking forward to hear from anybody who has a suggestion for me. Thanks.
Please open your eclipse.ini file from your eclipse folder with Note Pad and put the following permission into that.
-Dfile.encoding = UTF-8
Some more options as well:
For setting the encoding on a per WorkSpace basis, use Preferences->General->Workspace
To set the encoding on a per project basis open project properties and change to UTF-8
Hope this one help.
I think you'll need UTF-8 encoding for that.
These things are a little bit confusing. Reading this might clear some of the mist around encodings and character sets.
I think this may useful to you.
Keep this hebrew word in string.xml file. You can retrieve as
in String.xml
place hebrew word here
In java code:
String s=getString(R.string.hebrew_word);
Use this string as you want..

writing some characters like '<' in an xml file

since the beginning of my programmation, I used some special character like "<-", ""<<" im my string.xml in Eclipse while developping for Android.
All worked fine for one year, but today, i just wanted to make some minor changes and began to edit my xml files.
I get now compilation error on these characters because eclipse believe it's part of the xml blocks.
Any idea on how I could add this symbol "<" in my xml files?
Thank a lot.
Use
< for <
> for >
& for &
Another way to insert special character follow Moss guide: How can I write character & in android strings.xml by used Unicode definition:
Example:
<string name="item_unknown">\u003c Item Unknown \u003e</string>
which present in string :
< Item Unknown >
I stumbled upon this question, as I use HTML markup in my strings.
If you refer to the Android String Resources documentation,
in the section:
"Styling with HTML markup"
you will see that in strings.xml, you need to use &amplt; for an opening bracket, but you can safely use backslash and a closing bracket. For example:
<b>Text</b>
can be written as:
<b>Text</b>
in your strings.xml.
If using this HTML string in your code, you can use:
Html.fromHtml( getResources().getString(R.string.yourHTMLString )
and the output will be your bold string!

Categories

Resources