string_converter 0.0.2
string_converter: ^0.0.2 copied to clipboard
This package enables you to easily convert string characters in many formats to their value.
string_converter #
String type converter for Dart
- UTF8 <-> UTF16
- UTF8 <-> UTF32
Getting Started #
In the pubspec.yaml of your flutter project, add the following dependency:
dependencies:
...
string_converter:
Next we need to install this
# Dart
pub get
# Flutter
flutter packages get
In your library add the following import:
import 'package:string_converter/converter.dart';
Usage #
void main() {
final converter = StringConverter();
String text = "Hello";
// Convert utf8 to utf16
String utf16 = converter.toUTF16(text);
// \u0048\u0065\u006c\u006c\u006f
// Convert utf8 to utf32
String utf32 = converter.toUTF32(text);
// u+00000048u+00000065u+0000006cu+0000006cu+0000006f
// Convert utf16 to utf8
String utf8 = converter.toUTF8(utf16);
// Hello
}
You can use the extension method directly on the string too
print("hello".toUTF16());
// print \u0048\u0065\u006c\u006c\u006f
You can remove \u & u+ using the args remove
print(utf8.toUTF16(remove: true));
// print 0048 0065 006c 006c 006f
print(utf8.toUTF32(remove: true));
// print 00000048 00000065 0000006c 0000006c 0000006f