Created
September 29, 2019 15:14
-
-
Save saitbnzl/69264ca62e6acea58c8e10becf5bf0e0 to your computer and use it in GitHub Desktop.
hex string to ascii string in dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
String hexString = | |
"687474703A2F2F65727063727033752E706F61732E636F6D2E74723A383030302F4F415F48544D4C2F58787063417070536572766C65742E6A7370"; | |
List<String> splitted = []; | |
for (int i = 0; i < hexString.length; i = i + 2) { | |
splitted.add(hexString.substring(i, i + 2)); | |
} | |
String ascii = List.generate(splitted.length, | |
(i) => String.fromCharCode(int.parse(splitted[i], radix: 16))).join(); | |
print('${ascii}'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
String hexToAscii(String hex) {
List splitted = [];
for (int i = 0; i < hex.length; i = i + 2) {
splitted.add(hex.substring(i, i+2));
}
String ascii = List.generate(splitted.length, (index) => String.fromCharCode(int.parse(splitted[index], radix: 16))).join();
return ascii;
}