关于蓝牙搜索设备
发布于 6 年前 作者 twu 10831 次浏览 来自 问答

得到的name为‘4Vx’但是长度一直显示4


getBluetoothDevices:function(){

let that = this;

wx.getBluetoothDevices({

success: function (res4) {

console.log(res4);

for (let item of res4.devices) {

console.log(item.name.trim())

console.log(item.name.trim().length)

}

3 回复

只能通过判断字符编码区间来判断该字符是否为可见字符。

举例:如果你的设备名字使用ascii编码表示,那么如果该字符charCodeAt输出的编码小于32,则为不可见字符。

["",“4”,“V”,“x”]咨询一下该如何去除头上那个不可见的字符呢

你好,这种情况比较大的可能是名称中包含了不可见字符,可以考虑把字符串split后用charCodeAt方法打出不可见字符对应的编码值

回到顶部