Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Byte array, ASCII encoding
#1
How to create a byte array and convert it to ASCII encoding in QM ? 
I would like to know the equivalent in QM for the following PowerShell code. Thank you in advance.

Powershell Code:
Code:
Copy      Help
[Byte[]]$s = '72,80,32,90,82,50,50,119,0,0,0,0,0' -split ','
[Text.Encoding]::ASCII.GetString($s)
#2
simplest way not using and array at all
 
Code:
Copy      Help
str s="72,80,32,90,82,50,50,119,0,0,0,0,0"
s.replacerx("," "][")
s + "]"; s - "[";
out s.escape(0)
#3
Thanks for your help.
What is the equivalent QM code for the following PowerShell code?

Powershell Code:
Code:
Copy      Help
[Byte[]]$s = '228,189,160,229,165,189' -split ','
[Text.Encoding]::UTF8.GetString($s)
#4
The same code above will also work for that.
#5
QM strings are byte arrays. Why to create a byte array as ARRAY(byte) and convert to byte array as str?
#6
Kevin, Gintaras,  I apologize for the late reply.
I am amazed at the functionality of the member function "escape". It is incredibly powerful.
 
Quote:QM strings are byte arrays. Why to create a byte array as ARRAY(byte) and convert to byte array as str?

The text to be processed is from the output of the wmic command.
Is there a more easily understandable solution available?
#7
Task: wmic returns text "72,80,32,90,82,50,50,119,0,0,0,0,0", which is a comma-separated list of character codes, and need to convert it to string.
If all characters are ASCII, then Kevin's code works and is the simplest.
#8
Thanks for your explanation.

I have the following PowerShell code, which can escape text in a specific format into Unicode encoding. Is there a simple implementation method in QM?
The ultimate result of the code execution is to echo the text.

{"status":{"code":"1","message":"操作已经成功完成","created_at":"2023-09-23 06:58:47"}
 
Code:
Copy      Help
$Uni_s =@'
{"status":{"code":"1","message":"\u64cd\u4f5c\u5df2\u7ecf\u6210\u529f\u5b8c\u6210","created_at":"2023-09-23 06:58:47"}
'@
$match = {
    param ($v)
    [char][int]($v.Value.replace('\u', '0x'))
}
[regex]::Replace($Uni_s, '\\u[0-9-a-f]{4}', $match)


Forum Jump:


Users browsing this thread: 2 Guest(s)