I would like to convert a string from the ISO-8859-2 character set to the UTF-8 character set, but I can't find any solution in the Dart language. Is it possible to do it?
UTF-8 is a multibyte encoding that can represent any Unicode character. ISO 8859-1 is a single-byte encoding that can represent the first 256 Unicode characters. Both encode ASCII exactly the same way.
UTF-8. A Utf8Codec encodes strings to UTF-8 code units (bytes) and decodes UTF-8 code units to strings. The utf8 is the default implementation of Utf8Codec. Example: var encoded = utf8.
dart:convert library Null safety. Encoders and decoders for converting between different data representations, including JSON and UTF-8. In addition to converters for common data representations, this library provides support for implementing converters in a way which makes them easy to chain and to use with streams.
A string can be cast to an integer using the int. parse() method in Dart. The method takes a string as an argument and converts it into an integer.
There's no built-in converter for ISO-8859-2 in dart:convert. So you have to implement your own codec.
You can look at the code of Latin1Codec to implement a Latin2Codec
. Once ready you will be able to do :
import 'dart:convert';
final LATIN2 = new Latin2Codec();
main() {
List<int> bytesForIso_8859_2 = ...;
List<int> bytesForUTF8 = LATIN2.fuse(UTF8).encode(bytesForIso_8859_2);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With