简体   繁体   English

在javascript中将Uint8Array转换为字符串

[英]Convert Uint8Array to string in javascript

I'm running where *.exe to list all the exe from windows in electron application.and then launch some apps.It returns result in Uint8Array format.我正在运行 where *.exe 以列出电子应用程序中 Windows 中的所有 exe。然后启动一些应用程序。它以 Uint8Array 格式返回结果。

const { execSync } = require('child_process');
const exeFiles=execSync('where *.exe');
console.log( exeFiles); // this returns [97, 92,79,....]
console.log(exeFiles.toString());
// returns
//C:\Windows\System32\cacls.exe                                                                                           //C:\Windows\System32\calc.exe...        

I want result to be我希望结果是

[C:\Windows\System32\cacls.exe,C:\Windows\System32\calc.exe,...]        

if you want the result as an array, you can split the string based on the newline character and remove the last element如果您希望结果为数组,则可以根据换行符拆分字符串并删除最后一个元素

const resultArray = exeFiles.toString().split("\n")
resultArray.pop() // since last element will be empty string
console.log(resultArray);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM