Czy istnieje funkcja, która może zastąpić ciąg w ciągu jeden raz w określonym indeksie? Przykład:Korzystanie z .replace() na konkretny indeks
var string1="my text is my text";
var string2="my";
string1.replaceAt(string2,"your",10);
a wyjście wypadkowa będzie „mój tekst jest tekst”, lub:
var string1="my text is my text";
var string2="my";
string1.replaceAt(string2,"your",0);
w takim przypadku wynik będzie „tekst jest mój tekst”.
'string1 = string1.slice (0,10) + string1.slice (10) .replace (string2," your ");' - wrap in a custom ' replaceAt() 'funkcja jeśli jest wymagana. – nnnnnn
Zobacz też: http://stackoverflow.com/a/1431113/1757964 – APerson