得到的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)
}
網(wǎng)友回復(fù):
你好,這種情況比較大的可能是名稱中包含了不可見字符,可以考慮把字符串split后用charCodeAt方法打出不可見字符對應(yīng)的編碼值
["",“4”,"V","x"]咨詢一下該如何去除頭上那個不可見的字符呢
只能通過判斷字符編碼區(qū)間來判斷該字符是否為可見字符。
舉例:如果你的設(shè)備名字使用ascii編碼表示,那么如果該字符charCodeAt輸出的編碼小于32,則為不可見字符。
好的 謝謝