String replace in C#

Posted by ile on Stack Overflow See other posts from Stack Overflow or by ile
Published on 2010-04-02T13:13:55Z Indexed on 2010/04/02 13:23 UTC
Read the original article Hit count: 406

Filed under:
|
|
|

I'd like to use this method to create user-friendly URL. Because my site is in Croatian, there are characters that I wouldn't like to strip but replace them with another. Fore example, this string:
ŠÐCŽ šdccž
needs to be: sdccz-sdccz

So, I would like to make two arrays, one that will contain characters that are to be replaced and other array with replacement characters:

string[] character = { "Š", "Ð", "C", "C", "Ž", "š", "d", "c", "c", "ž" };
string[] characterReplace = { "s", "d", "c", "c", "z", "s", "d", "c", "c", "z" };

Finally, this two arrays should be use in some method that will take string, find matches and replace them. In php I used preg_replace function to deal with this. In C# this doesn't work:

s = Regex.Replace(s, character, characterReplace);


Would appreciate if someone could help. Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about string