-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,252
  • 1
  • 20
  • 41
2

Use regular expressions

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

jsFiddle

Claudio Redi
  • 67,454
  • 15
  • 130
  • 155
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,720
  • 2
  • 53
  • 77