Insert a character or string at the index position.

Syntax

TypeScript
import { stringInsertAt } from '@opentf/std';

stringInsertAt(str: string, index?: number, insertStr?: string): string;
Info

Default index = 0

Info

index must be a non-negative integer.

Examples

TypeScript
stringInsertAt() // It throws an error;

stringInsertAt('') //=> ''

stringInsertAt('', 0) //=> ''

stringInsertAt('', 1, 'abc') //=> 'abc'

stringInsertAt('a', 0, 'b') //=> 'ba'

stringInsertAt('a', 1, 'b') //=> 'ab'

stringInsertAt('a', 1, 'bc') //=> 'abc'

stringInsertAt('foo baz', 3, ' bar') //=> 'foo bar baz'
Last updated on
Edit this page