I have a string String str_one = "\uD83C\uDCA2"
that paints a poker card for me but I would like to know if it is possible to generate all the cards with a cycle for
.
I have tried to replace the last 2 characters, but could not. Also not having something like String str_two = "uD83CuDCA2"
and then using the str_two.replaceAll("u", "\u")
I need to know if there is another way to generate the cards taking advantage of the pattern they have in their representation Unicode
.
It doesn't have to be with strings, it can be with Character or with a hexadecimal representation, I just want to know if it is possible to generate the 52 cards taking advantage of the pattern they have.
Update:
I have used the string "symbol" as below for the creation of a letter and the set and get methods for "symbol" and "value", but later I will need the integer "codepoint", how do I get back from the string "symbol" to the integer "codepoint" ?
for (int c2 = 1, value=1; c2 <= 0xE; c2++, value++) {
for (int c1 = 0xA; c1 <= 0xD; c1++) {
if (c2!=0xC) {
str = String.format("1F0%X%X", c1, c2);
codePoint = Integer.parseInt(str, 16);
symbol = String.format("%c", codePoint);
cards.add(new Card (symbol, value));
} else {
value = 11;
}
}
System.out.println();
}
According to Wikipedia , the Unicode codes (in hexadecimal) for poker cards have the following pattern: they start with
1F0
, then a letter, from aA
toD
; then a number or letter, from1
to9
or fromA
toE
.❐ Code:
In Java it is possible to represent a number in hexadecimal literally . Just add the prefix
0x
to the desired number. And this can be leveraged to create twofor
nested loops, one for the first character and one for the second character. Namely:c1
goes from0xA
to0xD
andc2
goes from0x1
to0xE
, as required.❐ Exit:
──────────────
NOTE: Depending on the browser (and sometimes also on the operating system), the above characters may be rendered correctly: ?????????????? ??????????????????????????????????????
UPDATE
The code is modified, according to the OP 's comments , as follows: