buf.includes(value[, byteOffset][, encoding])
添加於:v5.3.0
參數
value
<string> | <Buffer> | <Uint8Array> | <integer> 要搜索的內容。byteOffset
<integer> 在buf
中從哪裏開始搜索。如果為負,則從buf
的末尾計算偏移量。 默認:0
。encoding
<string> 如果value
是一個字符串,這就是它的編碼。 默認:'utf8'
。- 返回: <boolean>
true
如果在buf
中找到value
,否則為false
。
等效於
。buf.indexOf() !== -1
import { Buffer } from 'node:buffer';
const buf = Buffer.from('this is a buffer');
console.log(buf.includes('this'));
// Prints: true
console.log(buf.includes('is'));
// Prints: true
console.log(buf.includes(Buffer.from('a buffer')));
// Prints: true
console.log(buf.includes(97));
// Prints: true (97 is the decimal ASCII value for 'a')
console.log(buf.includes(Buffer.from('a buffer example')));
// Prints: false
console.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));
// Prints: true
console.log(buf.includes('this', 4));
// Prints: false
const { Buffer } = require('node:buffer');
const buf = Buffer.from('this is a buffer');
console.log(buf.includes('this'));
// Prints: true
console.log(buf.includes('is'));
// Prints: true
console.log(buf.includes(Buffer.from('a buffer')));
// Prints: true
console.log(buf.includes(97));
// Prints: true (97 is the decimal ASCII value for 'a')
console.log(buf.includes(Buffer.from('a buffer example')));
// Prints: false
console.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));
// Prints: true
console.log(buf.includes('this', 4));
// Prints: false
相關用法
- Node.js Buffer buf.indexOf(value[, byteOffset][, encoding])用法及代碼示例
- Node.js Buffer buf.writeBigUInt64BE(value[, offset])用法及代碼示例
- Node.js Buffer buf.toString([encoding[, start[, end]]])用法及代碼示例
- Node.js Buffer buf.writeDoubleLE(value[, offset])用法及代碼示例
- Node.js Buffer buf.writeBigInt64LE(value[, offset])用法及代碼示例
- Node.js Buffer buf.keys()用法及代碼示例
- Node.js Buffer buf.writeFloatLE(value[, offset])用法及代碼示例
- Node.js Buffer buf.readFloatLE([offset])用法及代碼示例
- Node.js Buffer buf.readInt32LE([offset])用法及代碼示例
- Node.js Buffer buf.writeInt8(value[, offset])用法及代碼示例
- Node.js Buffer buf.swap32()用法及代碼示例
- Node.js Buffer buf.writeInt32LE(value[, offset])用法及代碼示例
- Node.js Buffer buf.writeIntLE(value, offset, byteLength)用法及代碼示例
- Node.js Buffer buf.values()用法及代碼示例
- Node.js Buffer buf.writeDoubleBE(value[, offset])用法及代碼示例
- Node.js Buffer buf.length用法及代碼示例
- Node.js Buffer buf.byteOffset用法及代碼示例
- Node.js Buffer buf.readUInt32BE([offset])用法及代碼示例
- Node.js Buffer buf.readDoubleLE([offset])用法及代碼示例
- Node.js Buffer buf.writeFloatBE(value[, offset])用法及代碼示例
- Node.js Buffer buf.readBigUInt64LE([offset])用法及代碼示例
- Node.js Buffer buf.readUInt16BE([offset])用法及代碼示例
- Node.js Buffer buf.writeInt16BE(value[, offset])用法及代碼示例
- Node.js Buffer buf.swap64()用法及代碼示例
- Node.js Buffer buf.readUInt8([offset])用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 buf.includes(value[, byteOffset][, encoding])。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。