“JavaScript -Zeichenfolge ersetzen” Code-Antworten

JavaScript ersetzen String

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

Js ersetzen alle

function replaceAll(str, find, replace) {
    var escapedFind=find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
    return str.replace(new RegExp(escapedFind, 'g'), replace);
}
//usage example
var sentence="How many shots did Bill take last night? That Bill is so crazy!";
var blameSusan=replaceAll(sentence,"Bill","Susan"); 
Grepper

JavaScript ersetzen

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

JavaScript -Text ersetzen

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

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

String.Replace JavaScript

//Replace the first match in a string
//If you wish to replace all matches, use the replaceAll() method.

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

JavaScript -Zeichenfolge ersetzen

const p = 'Its going to rain today and its going to rain tomorrow';

// Example of replacing all occurrances

// g = global search, which searches all instances
// i = case insensitive, which will match 'a' with 'A'
const regex = /rain/gi;
console.log(p.replace(regex, 'snow'));
// expected output: "Its going to snow today and its going to snow tomorrow"

// Example of replacing the first occurance
console.log(p.replace('rain', 'snow'));
// expected output: "Its going to snow today and its going to rain tomorrow"
JoeMoe

Ähnliche Antworten wie “JavaScript -Zeichenfolge ersetzen”

Fragen ähnlich wie “JavaScript -Zeichenfolge ersetzen”

Weitere verwandte Antworten zu “JavaScript -Zeichenfolge ersetzen” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen