- Node.js 教程
- Node.js - 首頁
- Node.js - 簡介
- Node.js - 環境搭建
- Node.js - 第一個應用程式
- Node.js - REPL 終端
- Node.js - 命令列選項
- Node.js - 包管理器 (NPM)
- Node.js - 回撥函式概念
- Node.js - 上傳檔案
- Node.js - 傳送郵件
- Node.js - 事件
- Node.js - 事件迴圈
- Node.js - 事件發射器
- Node.js - 偵錯程式
- Node.js - 全域性物件
- Node.js - 控制檯
- Node.js - 程序
- Node.js - 應用程式擴充套件
- Node.js - 打包
- Node.js - Express 框架
- Node.js - RESTful API
- Node.js - 緩衝區
- Node.js - 流
- Node.js - 檔案系統
- Node.js MySQL
- Node.js - MySQL 入門
- Node.js - MySQL 建立資料庫
- Node.js - MySQL 建立表
- Node.js - MySQL 插入資料
- Node.js - MySQL 查詢資料
- Node.js - MySQL 條件查詢
- Node.js - MySQL 排序
- Node.js - MySQL 刪除資料
- Node.js - MySQL 更新資料
- Node.js - MySQL 連線查詢
- Node.js MongoDB
- Node.js - MongoDB 入門
- Node.js - MongoDB 建立資料庫
- Node.js - MongoDB 建立集合
- Node.js - MongoDB 插入資料
- Node.js - MongoDB 查詢資料
- Node.js - MongoDB 查詢
- Node.js - MongoDB 排序
- Node.js - MongoDB 刪除資料
- Node.js - MongoDB 更新資料
- Node.js - MongoDB 資料限制
- Node.js - MongoDB 連線查詢
- Node.js 模組
- Node.js - 模組
- Node.js - 內建模組
- Node.js - 實用程式模組
- Node.js - Web 模組
- Node.js 有用資源
- Node.js - 快速指南
- Node.js - 有用資源
- Node.js - 討論
Node.js - Buffer.isEncoding() 方法
NodeJS 的Buffer.isEncoding()方法用於檢查給定的編碼值是否為受支援的字元編碼,如果是則返回true,否則返回false。
語法
以下是NodeJS Buffer.isEncoding() 方法的語法:
Buffer.isEncoding( encoding )
引數
encoding − (必需) 需要檢查的字元編碼值。
返回值
Buffer.isEncoding() 方法返回一個布林值 true/false。如果給定的編碼是受支援的有效編碼,則返回 true;否則返回 false。
示例
在這個示例中,我將測試 utf-8 和 hex 編碼,並檢視 Buffer.isEncoding() 方法的輸出。
const utf8encoding = Buffer.isEncoding('utf-8');
const hexencoding = Buffer.isEncoding('hex');
console.log("Result for utf-8 encoding is : "+ utf8encoding);
console.log("Result for hex encoding is : "+ hexencoding);
輸出
由於 utf-8 和 hex 都是正確的字元編碼,因此輸出將為 true。
Result for utf-8 encoding is : true Result for hex encoding is : true
示例
在這個示例中,我們將測試一個簡單的字串值,它不是編碼字元。
const helloencoding = Buffer.isEncoding('hello');
console.log("Result for hello encoding is : "+ helloencoding);
輸出
由於 "hello" 是無效的編碼值,因此 Buffer.isEncoding() 方法將返回 false。執行上述程式後,將生成以下輸出:
Result for hello encoding is : false
nodejs_buffer_module.htm
廣告
