Search code examples
flutterdartasciidart-pub

how to decode ASCII to text in dart


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


Solution

  • 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:

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