Using generic Unicode in Golang

In this article, we are going to cover how to use Unicode in Golang. In previous articles, we cover how to use CP-1252, Basic Latin, and IPA extensions. Since the list is long of all Unicode blocks we decide to write this article that covers them all.

The existent Unicode article illustrates how to use Unicode in Golang which looks like the following code snippet:

euroSign := '\u20AC' // -> euro sign unicode
fmt.Printf("Euro sign print format: %c\n", euroSign)

valueOnly := fmt.Sprintf("%c", euroSign) // If you only want the resulting string.
fmt.Println("Euro sign value: ", valueOnly)

In order to use Unicode from different blocks, the code implementation remains the same and the only thing that is needed is the desire Unicode. The list of the Unicode can be found in the Unicode blocks.

For demonstration purposes let say we want to use Unicode of the Greek and Coptic.

  • Select the Unicode block from the list
  • The Unicode for this character is 0370 and to use it in Go you need to add the \u prefix.

So your code should like this:

characterSymbol:= '\u0370'

And that’s it! The same goes for all other Unicode from the other blocks

Follow us:

Leave a Reply

Your email address will not be published. Required fields are marked *