views:

99

answers:

1

I'm using google translate to translate lots of words which I then store in DB, using this code:

http://www.developerfusion.com/community/blog-entry/8391765/translate-text-in-c-using-google- translate/

string txt = Translator.TranslateText("Cosmetics", "en|sr"); Response.Write(txt);

Translated text (string txt) shows correctly in browser: Козметика

but source for result looks like this: Козметика

Problem is I dont want to put that resulting scrambled string txt in DB, but instead want to place 'Козметика' same as I would be doing that from TextBox input. So what is basically going on here ?

I suppose it has to do something with codepages and unicode encoding.

Thanks

Daniel

+4  A: 

What you are getting is the HTML encoded entities of the characters in the text. Each character is being encoded into an HTML entity to get it to display properly in browsers.

To reverse it back into the original character, you can use the HttpUtility.HtmlDecode method:

string encoded = "Козметика";
string decoded = HttpUtility.HtmlDecode(encoded);

This will decode the encoded text back into Козметика.

adrianbanks