@stdlib/string-replace-before
v0.2.2
Published
Replace the substring before the first occurrence of a specified search string.
Downloads
14
Readme
replaceBefore
Replace the substring before the first occurrence of a specified search string.
Installation
npm install @stdlib/string-replace-before
Usage
var replaceBefore = require( '@stdlib/string-replace-before' );
replaceBefore( str, search, replacement )
Replaces the substring before the first occurrence of a specified search string.
var out = replaceBefore( 'beep boop', ' ', 'loop' );
// returns 'loop boop'
out = replaceBefore( 'beep boop', 'o', 'bar' );
// returns 'baroop'
Notes
- If a search string is not present in a provided string, the function returns the provided string unchanged.
- If a search string is an empty string, the function returns the provided string unchanged.
Examples
var replaceBefore = require( '@stdlib/string-replace-before' );
var out = replaceBefore( 'beep boop', 'p', 'see' );
// returns 'seep boop'
out = replaceBefore( 'Hello World!', 'xyz', 'foo' );
// returns 'Hello World!'
out = replaceBefore( 'Hello World!', '', 'foo' );
// returns 'Hello World!'
out = replaceBefore( '', 'xyz', 'foo' );
// returns ''
See Also
@stdlib/string-replace-before-cli
: CLI package for use as a command-line utility.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.