I have developed a small experimental program as a demo to use powershell and Xojo. I have a problem and it is that I can not convert the powershell encoding to Xojo, so the words with an accent (in Spanish) appear with wrong encoding in the text area of Xoxo. Tried with TextEncoding, but with woring results. Any suggestion? Thanks in advance for your help!
Program under OK button . Action:
DIM sh As New Shell
Dim f As FolderItem = GetTemporaryFolderItem
sh.Execute(“wmic csproduct get /all /format:htable”)
TextArea1.Text = sh.Result
Even if you added the HTML5 “< ! DOCTYPE html >” (without the spaces) to the start there’s a problem with the HTMLViewer that it doesn’t conform to the HTML5 standard and default to UTF-8. The only solution is to add the meta tag as Rick A suggests.
Just to be clear, the fact that you are putting it into a textarea first is part of your problem. The TextArea is going to try to coerce the text to be UTF8 if it has no encoding. You’d be better off just casting it first:
Dim data as string = DefineEncoding(sh.result, Encodings.WindowsLatin1)
Data = ConvertEncoding(data, Encodings.UTF8)
TextArea1.Text = data
Someone correct me if I’m wrong on the WindowsLatin1 thing. I’m typing this from memory.
There’s few things to observe from the presented sample from the OP:
1 . He gets the content set for a HTML output, that hints me the possibility of a standard current UTF-8 output.
2 . He gets such stream and moves it to a text box set to present utf-8 content, without changes, and it presents the accented content correctly. So, it seems native UTF-8 and seems to corroborate with the #1 suspicious.
3 . The bad presentation found in HTMLViewer shows a 2 byte coding of the accented char, compatible with an utf-8 coding, instead of a 1 byte extended charset as Latin1 or cp-1252.
So, I assumed that the coding was ok, but the HTMLViewer engine would need to be explicitly informed of the coding using the meta charset. And that way, it would be presented correctly.
Thank you very much, Rick. This seems to be the way, but I keep getting an unknown character symbol (question mark). I’m afraid that Powershell in Spanish is not very Xojo friendly, because even when I format in powershell with the command “format:list” in the text area it doesn’t appear as a list either, but all followed.
The PowerShell will generate it in Latin1, but you will need to tell your Xojo program that this is the case; it has no way of knowing, otherwise. Hence the DefineEncoding. Then use ConvertEncoding to convert that to UTF8 - this will actually alter the bytes you have. Then you can put that into a TextArea.