2

I want to write english transcription in console.

In debugger I have this səˈdʒest but in console I have s??d?est.

How to resolve this problem ? Thanks!

Up

Client for getting transcription

   class TranslationFormattedResult
    {
        public string Transcription { get; set; }
        public List<string> TranslatedWordList = new List<string>();
    }
    class TranslatorClient
    {
        private TranslationServiceSoapClient _client = new TranslationServiceSoapClient("TranslationServiceSoap");

       public async Task<TranslationFormattedResult> GetTranslationAsync(string word)
        {
            var result = await _client.GetTranslationAsync("er", "General",
                word,
                lang: "ru",
                limit: 3000,
                useAutoDetect: true,
                key: "",
                ts: "MainSite",
                tid: "");
            var translationResult = new TranslationFormattedResult {Transcription = await GetTranscriptionAsync(result)};
            return translationResult;
        }

        private async Task<string> GetTranscriptionAsync(TranslationResult result)
        {
            var task = new Task<string>(() =>
                                            {
                                                string pr = null;
                                                string pattern = "\\[.+\\]";
                                                var match = Regex.Match(result.result, pattern);
                                                if(match.Success)
                                                {
                                                    pr = match.Value.Trim('[', ']');
                                                }
                                                return pr;
                                            });
            task.Start();
            return await task;
        }
    }

And main method

class Program
            {
                static void Main(string[] args)
                {
//this works
                    var client = new TranslatorClient();            
             var ts = client.GetTranslationAsync("suggest")
                 .ContinueWith(r =>
                                   {
                                       var transcription = r.Result.Transcription;
                                       Console.OutputEncoding = Encoding.Unicode;
                                       Console.WriteLine(transcription);
                                       Console.WriteLine("press any key");
                                       Console.ReadKey();
                                   }
                     );
            ts.Wait();
    }
    }

text visualizer

BILL
  • 4,711
  • 10
  • 57
  • 96

2 Answers2

3

You should:

  1. set the OutputEncoding to Unicode: Console.OutputEncoding = Encoding.Unicode;
  2. run your program
  3. right click on the console window
  4. in the properties window change the console font and set it to Consolas.

class Program {
    static void Main( string[ ] args ) {
        Console.OutputEncoding = Encoding.Unicode;
        Console.WriteLine( "səˈdʒest" );
    }
}

The result in the console is:

enter image description here

Omar
  • 16,329
  • 10
  • 48
  • 66
  • 1
    @Victor Just FYI apparently you might need to be careful of MS's implementation of unicode according to commentor on this SO answer: http://stackoverflow.com/questions/388490/unicode-characters-in-windows-command-line-how (can't vouch for credibility of this as no authoritative source was provided as a reference - just bringing it to your attention in case it's an issue.) – Sepster Sep 29 '12 at 13:39
1

Is this Russian?

If so, try running chcp 866 at the command line.

Refer to this http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/chcp.mspx?mfr=true

This answer also suggests a specific (or at least, different) font may need to be selected (not sure if this applies to Russian or not) Unicode characters in Windows command line - how?

Community
  • 1
  • 1
Sepster
  • 4,800
  • 20
  • 38
  • I have english windows version. I am trying using all encodings. I haven't any good results. – BILL Sep 29 '12 at 13:28
  • @Victor To be clear, have you used this command at the command line? Unless the console knows which code-page to use, I don't think it'll correctly display what is output from your application. – Sepster Sep 29 '12 at 13:29