I am getting some strings from json. My string contains special characters like "æ" from Næstved an many more like "ø" from køkken. But When I set Text these strings to ant textview, I get my strings printed in unusual way.
Example: For køkken I get kø ;kken.
I think I need to encode or decode my string somewhere but where I don,t know.
Please help.
Thanks in advance
The displayed version of your string represents an HTML encoded entity. You might want to verify that it is not coming in this way in your JSON data, but in any case, to decode it you can use the StringEscapeUtils.unescapeHtml4 method from Apache Commons Lang:
final String escaped = "køkken";
System.out.println(StringEscapeUtils.unescapeHtml4(escaped));
Output:
køkken
Did you check out the Latin Coding for your characters? I know the Ash character can be coded with æ and will show up æ in the browser.
Here is the a list of codes
Hope this helps!
Related
I'm getting a JSON response string similar to this:
<strong>B.<\/strong> Because there is no indication of Miss Manette’s feelings
The string text that I'm receiving is full of tags like <strong>, <em> and ’
“
” etc. How can I parse it to a plain String with same features?
The only way I could think of is replacing such characters and using Html.fromHtml() method. Is there a built-in parser available? How could I parse such HTML text?
Use Html.fromHtml only. It'll parse most of the tags supplied and give you the formatted output. The point to note here is that not all of the HTML tags are supported by this method. Checkout this link for more information about what tags are supported. Also check this, though it's a bit old.
If you know what text you'll be parsing, and you have tags that aren't parsed by fromHtml, your best bet would be to replace them with empty string and then use this method.
Android Html.fromHtml function auto converts undesired text into hyperlinks.
Here is my code:
String htmlContent= "corners of nail.It has to";
textViewContent.setTextHtml.fromHtml(htmlContent));
textViewContent.setText(comment.getContent());
In above code Html.fromHtml treats "nails.It" as a link and converts it into hyperlink.
Here is the result of converted string.
One of the solution which I could think is, put space after fullstop.
Is there any good solution?
You can try something like this.
textViewContent.setText( Html.fromHtml("YOUR DESIRED TEXT"));
textViewContent. setMovementMethod(LinkMovementMethod.getInstance());
Hope it helps.
Provide space between dot and second statement
String htmlContent= "corners of nail. It has to";
textViewContent.setTextHtml.fromHtml(htmlContent));
textViewContent.setText(comment.getContent());
I am getting some Unicode string(emoji icons) from server in json string format.
My problem is strange and I am trying for last two days to resolve this issue. When I parse json and store all the Unicode string in an ArrayList<String> and try to set the text on TextView by getting value from the same ArrayList then it shows Unicode characters as :
Ghcghchgc\ud83d\ude03\ud83d\ude03fyju\ud83d\ude0c6\u20e3
and when the same string I set on textview by passing static value as :
textview.settext("Ghcghchgc\ud83d\ude03\ud83d\ude03fyju\ud83d\ude0c6\u20e3")
then the textview is showing perfect emojis.
I am stuck at this point. Can anybody please help me to resolve this issue or tell me if I am doing something wrong.
This sounds like you want to unescape your string that you've got from JSON. If you don't mind adding a library, Apache Commons has a String.unescapeJava function which does what you need. If you don't want to add that library, see this answer.
This is what has worked for me ( Kotlin version ):
textView.text = String(Character.toChars(0x1F389))
I am coding a maths app and I want to show special characters such as PI, E, or subscripts and all those things.
I want to show them on the xml file of the layout.
How can I do it?
Thank you guys for all!
You can use the Unicode value for the symbol, preceded by \u. For example, the pi character is "\u03C0"
This site: http://www.dionysia.org/html/entities/symbols.html has list of elements which can be used in xml. Just watch the second element. For example:
square = √
THen you need to conver it. For example:
String symbol = Html.fromHtml(square);
Alternative link is here: http://www.hrupin.com/2011/12/how-to-put-some-special-math-symbols-in-textview-editview-or-other-android-ui-element
The characters in a string resource are unicode. You can include special characters using the \unnnn notation.
There are many places to look up the unicode values on the web. Google found this one for me:
http://inamidst.com/stuff/unidata/
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..