英文:
Java / Scala - Get emojis from Hexacode
问题
如果我有一个表情符号的十六进制代码,如何从中生成完整的表情符号。如果它是一个单一的十六进制代码,我可以生成如下:
val str1 = "1F471"
val hex = Integer.parseInt(str1, 16)
println(new String(Character.toChars(hex)))
这会打印出 👱。然而,如果我想要打印出由第二个组件即 1F3FF 给出的带肤色的完整表情符号,需要做什么?
val str = "1F471 1F3FF"
val parts = str.split(" ").map { Integer.parseInt(it, 16) }
println(mergeEmojis(new String(Character.toChars(parts[0])), new String(Character.toChars(parts[1]))))
// 如何实现 mergeEmojis()?
如何实现 mergeEmojis()
?
英文:
Suppose I have a hexa code for an emoji, how can I generate the full emoji from the same. If its a single hexacode I am able to generate is as follows:
val str1 = "1F471"
val hex = Integer.parseInt(str1, 16)
println(new String(Character.toChars(hex)))
his prints 👱. However, if I want to print the full emoji with skin tone given by the second component i.e 1F3FF, what needs to be done?
val str = "1F471 1F3FF"
val parts = str.split(" ").map(x => Integer.parseInt(x, 16))
println(mergeEmojis(new String(Character.toChars(parts(0))), new String(Character.toChars(parts(1)))))
// how can mergeEmojis() be implemented?
答案1
得分: 0
根据 @Ackdari 的建议,连接字符可以起作用
// 将表情代码数组转换为表情字符串的方法
private def toEmoji(hexCodes: Array[Int]): String = {
var emojiCharsCombined: Array[Char] = Array.emptyCharArray
hexCodes.foreach(emojiComponent => {
val emojiChars: Array[Char] = Character.toChars(emojiComponent)
emojiCharsCombined = concat(emojiCharsCombined, emojiChars)
})
new String(emojiCharsCombined)
}
英文:
As suggested by @Ackdari, concatenating the characters works
// method to convert array of emoji codes to emoji string
private def toEmoji(hexCodes: Array[Int]): String = {
var emojiCharsCombined: Array[Char] = Array.emptyCharArray
hexCodes.foreach(emojiComponent => {
val emojiChars: Array[Char] = Character.toChars(emojiComponent)
emojiCharsCombined = concat(emojiCharsCombined, emojiChars)
})
new String(emojiCharsCombined)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论