forum-informatico
Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.
Ajude a Asast
Patrocinadores
Últimos assuntos
» Artigo ethereum
Replace all the occurrences in a String EmptyTer Set 24, 2019 1:16 pm por jpmartins

» Artigo Bitcoin
Replace all the occurrences in a String EmptyTer Set 24, 2019 1:13 pm por jpmartins

» Novo site para desportistas / New site for athletes
Replace all the occurrences in a String EmptyTer Dez 04, 2018 8:19 am por Admin

» Check used port with the command line
Replace all the occurrences in a String EmptyTer Dez 04, 2018 8:10 am por Admin

» Check the port where mariaDB is running
Replace all the occurrences in a String EmptySeg Dez 03, 2018 4:59 am por Admin

» Check the linux version
Replace all the occurrences in a String EmptySeg Dez 03, 2018 3:12 am por Admin

» Granting rights to a database for a user
Replace all the occurrences in a String EmptyQui Nov 29, 2018 2:04 am por Admin

» Create new user
Replace all the occurrences in a String EmptyQui Nov 29, 2018 2:01 am por Admin

» Change level of password security level
Replace all the occurrences in a String EmptyQui Nov 29, 2018 1:59 am por Admin

AdSense
Contributo

Replace all the occurrences in a String

Ir para baixo

Replace all the occurrences in a String Empty Replace all the occurrences in a String

Mensagem  Admin Seg maio 30, 2016 6:33 am

Here is how to replace all the occurrences of "something" using javascript:

Código:

String.prototype.replaceAll = function (find, replace) {
    var str = this;
    return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
};
....

var newValue = "abcdef".replaceAll("a", "1");


Result:
newValue = "1bcdef";
Admin
Admin
Admin

Mensagens : 607
Data de inscrição : 21/01/2008
Idade : 46

https://forum-informatico.forumeiros.com

Ir para o topo Ir para baixo

Ir para o topo

- Tópicos semelhantes

 
Permissões neste sub-fórum
Não podes responder a tópicos