Text encoding in NAV 2009 classic client?

I am working on a solution where i get response from an external API but the Danish characters are not properly encoded.

qyuvggjapksq.png

I get response in the InStream and then further store it in Big Text object.

How to encode my response in 'ISO-8859-1'

Thanks in advance :smile:

Best Answer

  • ftorneroftornero Member Posts: 524
    Answer ✓
    Hello @azharsaeedkhan, gessing that the response is in UTF-8. you can save the response to a file (InFile) and convert the file from UTF-8 to ISO-8859-1 with this code:
    IF ISCLEAR(Stream) THEN
      CREATE(Stream);
    IF ISCLEAR(Stream2) THEN
      CREATE(Stream2);
    Stream.Type := 2; // Text
    Stream.Charset := 'utf-8';
    Stream.Open;
    Stream.LoadFromFile(InFile);
    Stream2.Type := 2;
    Stream2.Charset := 'iso-8859-1';
    Stream2.Open;
    Stream2.Position := 0;
    Stream2.SetEOS;
    WHILE NOT Stream.EOS DO BEGIN
      Line := Stream.ReadText(1);
      Stream2.WriteText(Line);
    END;
    OutFile := ClientTempFileName('txt');
    Stream2.SaveToFile(OutFile, 2);
    [code]
    
    The variables
    
    [code]
    Name	DataType	Subtype	Length
    Stream	Automation	'Microsoft ActiveX Data Objects 2.5 Library'.Stream	
    Stream2	Automation	'Microsoft ActiveX Data Objects 2.5 Library'.Stream	
    Line	Text		1024
    OutFile	Text		1024
    [code]
    
    
    Function ClientTempFileName
    
    [code]
    ClientTempFileName(FileExtension : Text[250]) FileName : Text[1024]
    TempFile.CREATETEMPFILE;
    FileName := TempFile.NAME + '.' + FileExtension;
    TempFile.CLOSE;
    [code]
    
    The variables
    
    [code]
    Name	DataType	Subtype	Length
    TempFile	File		
    

    Regards

Answers

  • ftorneroftornero Member Posts: 524
    Answer ✓
    Hello @azharsaeedkhan, gessing that the response is in UTF-8. you can save the response to a file (InFile) and convert the file from UTF-8 to ISO-8859-1 with this code:
    IF ISCLEAR(Stream) THEN
      CREATE(Stream);
    IF ISCLEAR(Stream2) THEN
      CREATE(Stream2);
    Stream.Type := 2; // Text
    Stream.Charset := 'utf-8';
    Stream.Open;
    Stream.LoadFromFile(InFile);
    Stream2.Type := 2;
    Stream2.Charset := 'iso-8859-1';
    Stream2.Open;
    Stream2.Position := 0;
    Stream2.SetEOS;
    WHILE NOT Stream.EOS DO BEGIN
      Line := Stream.ReadText(1);
      Stream2.WriteText(Line);
    END;
    OutFile := ClientTempFileName('txt');
    Stream2.SaveToFile(OutFile, 2);
    [code]
    
    The variables
    
    [code]
    Name	DataType	Subtype	Length
    Stream	Automation	'Microsoft ActiveX Data Objects 2.5 Library'.Stream	
    Stream2	Automation	'Microsoft ActiveX Data Objects 2.5 Library'.Stream	
    Line	Text		1024
    OutFile	Text		1024
    [code]
    
    
    Function ClientTempFileName
    
    [code]
    ClientTempFileName(FileExtension : Text[250]) FileName : Text[1024]
    TempFile.CREATETEMPFILE;
    FileName := TempFile.NAME + '.' + FileExtension;
    TempFile.CLOSE;
    [code]
    
    The variables
    
    [code]
    Name	DataType	Subtype	Length
    TempFile	File		
    

    Regards
  • azharsaeedkhanazharsaeedkhan Member Posts: 37
    ftornero wrote: »
    Hello @azharsaeedkhan, gessing that the response is in UTF-8. you can save the response to a file (InFile) and convert the file from UTF-8 to ISO-8859-1 with this code:
    IF ISCLEAR(Stream) THEN
      CREATE(Stream);
    IF ISCLEAR(Stream2) THEN
      CREATE(Stream2);
    Stream.Type := 2; // Text
    Stream.Charset := 'utf-8';
    Stream.Open;
    Stream.LoadFromFile(InFile);
    Stream2.Type := 2;
    Stream2.Charset := 'iso-8859-1';
    Stream2.Open;
    Stream2.Position := 0;
    Stream2.SetEOS;
    WHILE NOT Stream.EOS DO BEGIN
      Line := Stream.ReadText(1);
      Stream2.WriteText(Line);
    END;
    OutFile := ClientTempFileName('txt');
    Stream2.SaveToFile(OutFile, 2);
    [code]
    
    The variables
    
    [code]
    Name	DataType	Subtype	Length
    Stream	Automation	'Microsoft ActiveX Data Objects 2.5 Library'.Stream	
    Stream2	Automation	'Microsoft ActiveX Data Objects 2.5 Library'.Stream	
    Line	Text		1024
    OutFile	Text		1024
    [code]
    
    
    Function ClientTempFileName
    
    [code]
    ClientTempFileName(FileExtension : Text[250]) FileName : Text[1024]
    TempFile.CREATETEMPFILE;
    FileName := TempFile.NAME + '.' + FileExtension;
    TempFile.CLOSE;
    [code]
    
    The variables
    
    [code]
    Name	DataType	Subtype	Length
    TempFile	File		
    

    Regards

    Hi @ftornero

    Thank you soo much for the help. I was Reading BigText into Stream object that was giving me some weird results.

    Now after using files, it is working as required :)
Sign In or Register to comment.