Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

slice

Slice UTF-16 code units from a string.

Usage

var slice = require( '@stdlib/string/base/slice' );

slice( str, start, end )

Slices UTF-16 code units from a string.

var out = slice( 'last man standing', 1, 17 );
// returns 'ast man standing'

out = slice( 'Hidden Treasures', 0, 6 );
// returns 'Hidden'

out = slice( 'foo bar', 2, 7 );
// returns 'o bar'

out = slice( 'foo bar', -1, 7 );
// returns 'r'

The function accepts the following arguments:

  • str: input string.
  • start: slice start index (inclusive).
  • end: slice end index (exclusive).

Examples

var slice = require( '@stdlib/string/base/slice' );

var str = slice( 'presidential election', 1, 21 );
// returns 'residential election'

str = slice( 'JavaScript', 4, 10 );
// returns 'Script'

str = slice( 'The Last of the Mohicans', 5, 24 );
// returns 'ast of the Mohicans'