-1

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

This function only replaces the first Ő character:

str.replace('Ő','ö');
0

3 Answers 3

4

Use regexp and global:

str.replace(/Ő/g,'ö')
Sign up to request clarification or add additional context in comments.

Comments

2

Use regular expressions

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

jsFiddle

Comments

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.

1 Comment

I agree, regex is definitely worth taking the time to learn :-)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.