Skip to content

Instantly share code, notes, and snippets.

@asissuthar
Created October 4, 2022 10:02
Show Gist options
  • Save asissuthar/cf8fcf0b3be968b1f341e537eb423163 to your computer and use it in GitHub Desktop.
Save asissuthar/cf8fcf0b3be968b1f341e537eb423163 to your computer and use it in GitHub Desktop.
Convert country code (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) to Flag emoji using Kotlin functions.
fun countryFlag(code: String) = code
.uppercase()
.split("")
.filter { it.isNotBlank() }
.map { it.codePointAt(0) + 0x1F1A5 }
.joinToString("") { String(Character.toChars(it)) }
println(countryFlag("in"))
// output 🇮🇳
@AndroidDeveloperLB
Copy link

AndroidDeveloperLB commented Aug 2, 2024

I see. Thanks.
So if I want to check the values, that it is in the range, each of the 2 characters should be between 0x1F1E6 and 0x1F1FF , right?

That's about the output.
The input should just be between A and Z, right (from AA to ZZ)?

@asissuthar
Copy link
Author

each of the 2 characters should be between 0x1F1E6 and 0x1F1FF , right?

Correct

@AndroidDeveloperLB
Copy link

OK thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment