String
insertAt

Insert a character or string at the index position.

Syntax

import { insertAt } from '@opentf/std';
 
insertAt(str: string, index?: number, insertStr?: string): string;

Default index = 0

Examples

insertAt() // It throws an error;
 
insertAt('') //=> ''
 
insertAt('', 0) //=> ''
 
insertAt('', 1, 'abc') //=> 'abc'
 
insertAt('a', 0, 'b') //=> 'ba'
 
insertAt('a', 1, 'b') //=> 'ab'
 
insertAt('a', 1, 'bc') //=> 'abc'
 
insertAt('foo baz', 3, ' bar') //=> 'foo bar baz'

Try