Home > Software engineering >  how to decode ASCII to text in dart
how to decode ASCII to text in dart

Time:06-10

So I need to decode a from ASCII to text:

ex: &#1601 &#1614 &#1573 &#1616 &#1606 &#1617 &#1614 &#32 &#1649 &#1604 &#1618 &#1580& #1614 &#1606 &#1617 &#1614 &#1577 &#1614

All separated by ";"

would be: فَإِنَّ ٱلْجَنَّة

I looked into dart:convert package and it's Ascii decoder it doesn't seems to be an answer. any thoughts

CodePudding user response:

You need understand that &#1601 is html definition of 1601 decimal character code on ASCII table.

on Dart to get char from code you need just call String.fromCharCode(1601) -> ف

Here is some example from your case

String str = "&#1601 &#1614 &#1573 &#1616 &#1606 &#1617 &#1614 &#32 &#1649 &#1604 &#1618 &#1580 &#1614 &#1606 &#1617 &#1614 &#1577 &#1614";
var maped = str.split(' ').map((charCode) {
    return String.fromCharCode(
        int.parse(charCode.replaceAll('&#', ''))
    );  
}).join('');
  
  print(maped);

OUTPUT:

فَإِنَّ ٱلْجَنَّةَ

  • Related