Text encoding in NAV 2009 classic client?

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

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

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

0
Best 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
Regards1
Answers
-
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
Regards1 -
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 required0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions