Browse Source

doc: add buf.indexOf encoding param with example

PR-URL: https://github.com/nodejs/node/pull/3373
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
v5.x
Karl Skomski 9 years ago
committed by Rod Vagg
parent
commit
2dde0f08c9
  1. 16
      doc/api/buffer.markdown

16
doc/api/buffer.markdown

@ -532,17 +532,18 @@ console.log(b.toString());
// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh // Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
``` ```
### buf.indexOf(value[, byteOffset]) ### buf.indexOf(value[, byteOffset][, encoding])
* `value` String, Buffer or Number * `value` String, Buffer or Number
* `byteOffset` Number, Optional, Default: 0 * `byteOffset` Number, Optional, Default: 0
* `encoding` String, Optional, Default: `utf8`
* Return: Number * Return: Number
Operates similar to [`Array#indexOf()`][] in that it returns either the Operates similar to [`Array#indexOf()`][] in that it returns either the
starting index position of `value` in Buffer or `-1` if the Buffer does not starting index position of `value` in Buffer or `-1` if the Buffer does not
contain `value`. The `value` can be a String, Buffer or Number. Strings are contain `value`. The `value` can be a String, Buffer or Number. Strings are by
interpreted as UTF8. Buffers will use the entire Buffer (to compare a partial default interpreted as UTF8. Buffers will use the entire Buffer (to compare a
Buffer use [`Buffer#slice()`][]). Numbers can range from 0 to 255. partial Buffer use [`Buffer#slice()`][]). Numbers can range from 0 to 255.
```js ```js
const buf = new Buffer('this is a buffer'); const buf = new Buffer('this is a buffer');
@ -559,6 +560,13 @@ buf.indexOf(new Buffer('a buffer example'));
// returns -1 // returns -1
buf.indexOf(new Buffer('a buffer example').slice(0,8)); buf.indexOf(new Buffer('a buffer example').slice(0,8));
// returns 8 // returns 8
const utf16Buffer = new Buffer('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
utf16Buffer.indexOf('\u03a3', 0, 'ucs2');
// returns 4
utf16Buffer.indexOf('\u03a3', -4, 'ucs2');
// returns 6
``` ```
### buf.includes(value[, byteOffset][, encoding]) ### buf.includes(value[, byteOffset][, encoding])

Loading…
Cancel
Save