Home >Backend Development >Golang >How Can I Convert Non-UTF-8 Text (e.g., Windows-1256) to UTF-8 in Go?
Encoding Conversion in Go: Transform Text from Non-UTF-8 to UTF-8
The conversion of text from one encoding to another, such as from Windows-1256 Arabic to UTF-8, is a common task in software development. In Go, this can be accomplished with the encoding package.
The encoding package provides support for a wide range of encodings, including Windows-1256. To convert text from Windows-1256 to UTF-8, you can use the charmap package, which provides a Windows-1256 encoding option.
Here's an example that illustrates the process:
In this example, the transform.NewReader function is used to create a decoder that reads from the Windows-1256 encoded string. This decoder is then used to convert the string to UTF-8, resulting in a UTF-8 encoded output string that is printed to the console.
The above is the detailed content of How Can I Convert Non-UTF-8 Text (e.g., Windows-1256) to UTF-8 in Go?. For more information, please follow other related articles on the PHP Chinese website!