“Texte JavaScript Remplacer” Réponses codées

JavaScript remplacer la chaîne

var str = "JavaScript replace method test";
var res = str.replace("test", "success");  
//res = Javscript replace method success
Batman

Remplacer JavaScript

var res = str.replace("find", "replace");
Friendly Hawk

Texte JavaScript Remplacer

let text = "I     love you"
text = text.replace( / +/g, '_') // replace with underscore ('_')

console.log(text) // I_love_you
Asiful Islam Sakib

Remplacer JavaScript

const p = 'dog dog cat rat';
const regex = /dog/gi;

console.log(p.replace(regex, 'cow'));
//if pattern is regular expression all matches will be replaced
//output: "cow cow cat rat"

console.log(p.replace('dog', 'cow'));
// If pattern is a string, only the first occurrence will be replaced.
//output: "cow dog cat rat"
Batman

JavaScript la méthode remplacer ()

let text = "Please visit Microsoft!";
let newText = text.replace("Microsoft", "W3Schools");
naly moslih

remplacer en javascript

var str = "Please locate where 'locate' occurs!";

str.replace("locate", "W3Schools"); //replace only replace first match from string
str.replace(/LOCATE/i, "W3Schools"); // i makes it case insensitive
str.replace(/LOCATE/g, "W3Schools"); // g replace all matches from string rather than replacing only first
Dangerous Duck

Réponses similaires à “Texte JavaScript Remplacer”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code