0

I know how to replace single character in string, but what if i want to replace multiple characters?

var replaceMe = "Přemysl Oráč Šestý";


$("body").append( replaceMe );

For example:

  • ě = e;
  • č = c;
  • ď = d;
  • ř = r;

and so on. In my case Přemysl Oráč Šestý should be Premysl Orac Sesty

How to do that if I have multiple characters?

Here is my codepen http://codepen.io/anon/pen/RaXvjo?editors=0010

Karolina Ticha
  • 531
  • 4
  • 19

1 Answers1

1

Just call .replace() method multiple times:

var replaceMe = "Přemysl Oráč Šestý";

var replaced = replaceMe
  .replace(/ě/g, "e")
  .replace(/č/g, "c")
  .replace(/ď/g, "d")
  .replace(/ř/g, "r")

$("body").append(replaced);
Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177