ConvertEncoding…?

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
HTMLViewer1.LoadPage(TextArea1.Text, f)

Try

<html>
<head>
 <meta charset="UTF-8">
</head>
<h3>
...
sh.Execute(“wmic csproduct get /all /format:htable”)
Var s As String = sh.Result.Replace("<html>", "<html><head><meta charset=""UTF-8""></head>")
HTMLViewer1.LoadPage(s, f)

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.

feedback://showreport?report_id=64259

Should you be using DefineEncoding?

1 Like

sh.Result.DefineEncoding(Encodings. …)

Powershell and command prompt should be using encodings.WindowsANSI (CP-1252).

DefineEncoding should suffice.

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
HTMLViewer1.LoadPage(data, f)

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.

Thank you very much, Ian!

1 Like

Thank you very much, Tim for the suggestion! Will try it as with Greg’s sample.

That ONE would output a Windows charset as people mentioned. I would define it as Latin1 as Greg said.

Thank you very much, Greg. I’ll try your solution. I tried to do it with Convert Encoding, but did no get the point of wich encodings to use.

Thanks a lot, Rick. Yes, Greg’s sample seems o be the solution.

1 Like

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.

Thanks a lot, Greg!

Thank you very much, Tim!