Swedish Characters in Regular expression

How do I make my Regexp to show swedish characters as they are meant: öåä
They currently get returned as a ¿
If I get a match for example Gött then will be displayed as G¿tt

My code is below
Match LocalT = Regex.Match(result, "<h1><span property=\"item\">(?<LocalT>.*?)</span>");
                    
MessageBox.Show(LocalT.Groups["LocalT"].Value);

Open in new window

LVL 1
SmykenAsked:
Who is Participating?
 
Pui_YunCommented:
Hi Smyken,
Your code works for me (see below).  What I think is happening is when you read in the string result, you are using a StreamReader which is reading the Encoding of the document wrong.  Try to set the encoding to UTF8 manually.

Hope this helps.
P.
//This works:
string result = @"<h1><span property=""item"">öåä</span>";
Match LocalT = Regex.Match(result, "<h1><span property=\"item\">(?<LocalT>.*?)</span>");
MessageBox.Show(LocalT.Groups["LocalT"].Value);


//Try this for reading the string:
string result = "";
            using (StreamReader srInput = new StreamReader(strInputPath, Encoding.UTF8))
            {
                result =  srInput.ReadToEnd();
            }

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.