-1

How is it possible, to replace ŐŰőű characters to ÖÜöü in javascript?

This function only replaces the first Ő character:

str.replace('Ő','ö');
asdaq7
  • 93
  • 1
  • 4

3 Answers3

4

Use regexp and global:

str.replace(/Ő/g,'ö')
maximkou
  • 5,034
  • 1
  • 17
  • 40
2

Use regular expressions

str = str
   .replace(/Ő/g,'ö')
   .replace(/Ű/g,'Ü')
   .replace(/ő/g,'ö')
   .replace(/ű/g,'ü')

jsFiddle

Claudio Redi
  • 65,896
  • 14
  • 126
  • 152
2

You can either use regex (as provider by Claudio Redi) or use global flag 'g':

str.replace("Ő", "ö", "g")
str.replace("Ű", "Ü", "g")
str.replace("ő", "ö", "g")
str.replace("ű", "ü", "g")

see reference

I personally prefer regex. Takes some time to learn them, but it is worth it.

R. Oosterholt
  • 7,183
  • 2
  • 50
  • 72