I am trying to convert the English numbers (1, 2, 3) to Bengali numbers (১, ২, ৩).
For example, if I get 10000, then I want to show like ১০,০০০.
I can replace the number one by one with the Bengali counterpart using replaceAll method
But I want to know if there is an alternative solution to do that instead of the above.
Use this:
val convertedString = String.format(Locale.forLanguageTag("bn"), "%d", 1234567890)
I have used NumberFormat from popular library Intl and converted it easily like below
NumberFormat("##,##,##,###", "bn").format(10000)
And the output is:
১০,০০০
Related
I've been trying to find a good way to be able to keep only emojis and letters in a given text, but every article I found, I didn't have success with .
I've tried to use regex, but seems that I can not make it work.
I've tried to use emoji4j but it seems that this library is working with emojis in this form ":)", which don't help me, because my emojis are groups of unicode characters.
The result I want is the following :
"This is. a text 👨👩👧👦,,1234" => "This is a text 👨👩👧👦"
"👨👩👧👦" => "👨👩👧👦"
"👨👩👧👦😃123abc👨👩👧👦" => "👨👩👧👦😃abc👨👩👧👦"
Here's the emoji regex : ?:[\u2700-\u27bf]|(?:[\ud83c\udde6-\ud83c\uddff]){2}|[\ud800\udc00-\uDBFF\uDFFF]|[\u2600-\u26FF])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|[\ud83c\udffb-\ud83c\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:[\ud83c\udde6-\ud83c\uddff]){2}|[\ud800\udc00-\uDBFF\uDFFF]|[\u2600-\u26FF])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|[\ud83c\udffb-\ud83c\udfff])?)*|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|[\ud83c\udd70-\ud83c\udd71]|[\ud83c\udd7e-\ud83c\udd7f]|\ud83c\udd8e|[\ud83c\udd91-\ud83c\udd9a]|[\ud83c\udde6-\ud83c\uddff]|[\ud83c\ude01-\ud83c\ude02]|\ud83c\ude1a|\ud83c\ude2f|[\ud83c\ude32-\ud83c\ude3a]|[\ud83c\ude50-\ud83c\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff] .
If I try something like :
val regex = "the_whole_regex_above | [^a-zA-Z]".toRegex()
myText.replace(regex,""), it won't replace anything, basically every character will pass
Basically I want to achieve pretty much the same thing as in this question, but using Kotlin.
You want to remove all punctuation, symbols (other than those used to form emojis) and digits.
To do that, you may use
myText = myText.replace("""[\p{N}\p{P}\p{S}&&[^\p{So}]]+""".toRegex(), "")
See the online Kotlin demo.
Details
[ - start of a character class that matches:
\p{N} - any Unicode digit
\p{P} - any Unicode punctuation proper
\p{S} - any Unicode symbol
&&[^\p{So}] - BUT the Unicode symbols belonging to Symbol, other Unicode category that are mostly used to form emojis
]+ - 1 or more occurrences.
i have a simple Memory Game as Project. For the Memory Tiles I wanted to use Emojis. I tried to use it that way:
emojiCard.setText(new String(Character.toChars(Integer.parseInt(1F60D, 16))));
now I just have to save 1F60D to a variable and can show the emoji.
that works for simple emojis but I cannot use the "new" ones because then i have to use surrogate pairs and I don't know how to do this.
Is there a better way ? like saving the unicode ?
sorry i'am really new to android development and tried already a lot of things.
Thanks.
Integer.parseInt() takes a String as input, so presumably you meant to say Integer.parseInt("1F60D", 16) instead. Which would be wasted overhead when you can simply pass a numeric 0x1F60D literal to Character.toChars() instead.
Java strings use UTF-16 encoding. When encoded to UTF-16, codepoint U+1F60D uses surrogate pairs, so surrogates is not your issue.
Assuming you are referring to how newer emojis support modifiers (to change their genders, colors, etc), then that has nothing to do with surrogates. You simply append the modifier codepoint(s) you want after the base emoji codepoint. For example:
emojiCard.setText(new String(Character.toChars(0x1F466)) + new String(Character.toChars(0x1F3FE)));
(👦 + 🏾 = 👦🏾)
How can I display some calculus with variables and indices as a String in android? Or even just a simple radical sign over some numbers?
TextView in Android supports UTF-8, so you can use non-typical characters like: ≠, ÷, =, ∑, ∈, etc.
Full list here: http://en.wikipedia.org/wiki/List_of_mathematical_symbols
You can use unicodes
You can get list of unicodes from this link
for example
If you want to use ∑ use
android:text="/u2211"
attribute in xml
OR
textView.setText("/u2211")
You can also use in HTML like
.setText(Html.fromHtml("X<sup>2</sup>")); for X^2
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/
Before I go reinventing the wheel, does Android have any facility for converting an integer to an ordinal string with multi-language support? That is, it would convert the integer 3 to "3rd" in English and "3eme" in French.
I can see how to do this myself using a bit of logic along with Android's automatic string substitution, but thought that this surely must have been encountered by others, and not just for use with dates.
Java nor Android have support for creating ordinal strings. Android does have support for creating plural string resources, but not ordinals.
If the range for which you need ordinals is limited, then you are probably best to use a <string-array> to define them:
<string-array name="ordinals">
<item>zeroth</item>
<item>1st</item>
<item>2nd</item>
<item>3rd</item>
<item>4th</item>
<item>5th</item>
<item>6th</item>
</string-array>
and then access it via:
String ordinal = getResources().getStringArray(R.array.ordinals)[count];
Of course this doesn't get you automatic translation into other languages - you have to do that yourself (and if your count goes outside the range in this simplistic code you will get an exception).
Just for future reference, I came across this issue and discovered that now you can use the ICU MessageFormat to do something like this:
import android.icu.text.MessageFormat
fun toOrdinal(day: String): String {
val formatter = MessageFormat("{0,ordinal}", Locale.getDefault())
return formatter.format(arrayOf(day.toInt()))
}
You will get these results:
1 -> 1st
2 -> 2nd
3 -> 3rd
4 -> 4th
5 -> (...)