0.2.1 • Published 2 months ago

@stdlib/string-base-replace-before v0.2.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 months ago

replaceBefore

NPM version Build Status Coverage Status

Replace the substring before the first occurrence of a specified search string.

Installation

npm install @stdlib/string-base-replace-before

Usage

var replaceBefore = require( '@stdlib/string-base-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-base-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 ''

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

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2024. The Stdlib Authors.