String
replaceAt

Replace a character or string at the index position.

Syntax

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

Default index = 0

Examples

replaceAt(); // Throws error
 
replaceAt(""); //=> ''
 
replaceAt("", 0); //=> ''
 
replaceAt("", 0, "a"); //=> 'a'
 
replaceAt("", 1, "abc"); //=> 'abc'
 
replaceAt("a"); //=> ''
 
replaceAt("abc"); //=> 'bc'
 
replaceAt("abc", 1); //=> 'ac'
 
replaceAt("abc", 5); //=> 'abc'
 
replaceAt("abc", 1, ""); //=> 'ac'
 
replaceAt("abc", 0, "z"); //=> 'zbc'
 
replaceAt("iphone", 1, "P"); //=> 'iPhone'

Try