insertStr() function
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
函数“insertStr”接受一个字符串、一个起始索引和一个字符,并返回一个新字符串,其中在指定索引处插入了该字符。
Signature:
typescript
declare function insertStr(str: string, start: number, char: string): string;
declare function insertStr(str: string, start: number, char: string): string;
Parameters
Parameter | Type | Description |
---|---|---|
str | string | str 参数是一个字符串,表示将在其中插入字符的原始字符串。 |
start | number | start 参数是应在字符串中插入字符的索引。 |
char | string | “char”参数是一个字符串,表示要插入到原始字符串中的字符或子字符串。 |
Returns:
string
{string} - 在指定索引处插入指定字符的新字符串。
Example
JavaScript
let str = 'Hello'; insertStr(str, 2, 'X') // 'HeXllo'
let str = 'Hello'; insertStr(str, 2, 'X') // 'HeXllo'