// JavaScript

A replacement function that can be used instead of JavaScript Replace

As you know, to replace a string in JavaScript, we call the replace function.

var str = "kırmızı arabaları çok seviyorum!";
var res = str.replace("kırmızı", "mavi");

a function that will write blue instead of red.

However, in some cases, especially with very long strings, I’ve experienced that this function may not work properly. Instead, you can use the following code for string replacement operations. You’ll get much more stable results.

var sonuc = degistirilecekString.split("kırmızı").join("mavi");

Also, it can cause problems when parsing an encoded URL; the following command will solve your problem.

var decode_string = decodeURIComponent(url_string);

 

// JOIN THE CONVERSATION

Share your experience

Bir sorunun, farklı bir çözümün veya eklemek istediğin bir notun var mı? Giriş yapmadan da yazabilirsin.

// KEEP READING

One more note.

All posts ↗︎