Convert uint16 array to string

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

Convert uint16 array to string



I have an array of uint16 coming from WinAPI PROCESSENTRY32.szExeFile that I wanna convert to a string.


PROCESSENTRY32.szExeFile



Here's my var type


var hello [260]uint16



now I need to convert hello to a string. How can I do that?



Edit



Here's what I've tried:


func szExeFileToString(ByteString [260]uint16) string
b := make(byte, len(ByteString))

for i, v := range ByteString
b[i] = byte(v)


return string(b)



However, this returns pretty weird strings...
result (the function should convert Windows process names in the PROCESSENTRY32.szExeFile (-> [260]uint16) type to string)


PROCESSENTRY32.szExeFile


[260]uint16





What format should the string take? What have you tried? Show your code. What problems did you encounter?
– Flimzy
9 hours ago





@Flimzy question edited.
– Micheal N.
8 hours ago





Why downvoting my question? I don't see what's wrong with it.
– Micheal N.
8 hours ago





Don't use links to images of text--copy and paste the text directly into the question instead.
– Flimzy
4 hours ago





Don't put the solution in your question--instead create an answer.
– Flimzy
4 hours ago




1 Answer
1



package windows



import "golang.org/x/sys/windows"


import "golang.org/x/sys/windows"



func UTF16ToString


func UTF16ToString(s uint16) string



UTF16ToString returns the UTF-8 encoding of the UTF-16 sequence s,
with a terminating NUL removed.



For example,


package main

import (
"fmt"
"golang.org/x/sys/windows"
)

func main()
var szExeFile [260]uint16
szExeFile = [260]uint16'e', 'x', 'e', 'F', 'i', 'l', 'e'
exeFile := windows.UTF16ToString(szExeFile[:])
fmt.Println(exeFile)



Output:


exeFile






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

Trying to Print Gridster Items to PDF without overlapping contents

Hystrix command on request collapser fallback