HarmonyOS 鸿蒙Next中怎么实现string解码去掉\n
HarmonyOS 鸿蒙Next中怎么实现string解码去掉\n 鸿蒙中怎么实现string解码去掉
3 回复
base64解码默认就是去掉\n进行解码的,可以参考这个demo:
let base64Helper = new util.Base64Helper();
let array = 'TWFQWE\n';
base64Helper.decode(array).then((val) => {
console.info(val.toString());
})
更多关于HarmonyOS 鸿蒙Next中怎么实现string解码去掉\n的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
replaceAll(’\n’, ‘’)试下
在HarmonyOS鸿蒙Next中,可以通过使用字符串的replace
方法来实现去掉\n
。具体操作如下:
let str = "Hello\nWorld\n";
let newStr = str.replace(/\n/g, "");
console.log(newStr); // 输出: HelloWorld
在这个例子中,replace
方法使用了正则表达式/\n/g
来匹配所有的换行符\n
,并将其替换为空字符串""
,从而去掉了所有的换行符。