Bharani
Bharani

Reputation: 107

Japanese source code corrupted after upgrading Visual Studio 2010 to 2013

I have migrated an application developed in Visual Studio 2010 and upgraded to 2013. Now I see all program comments in Japanese in 2010 are displaying as junk data as follows.

// Ží—ÞC Ŭ’lC ’†ŠÔ’lC Å‘å’lCŬˆÚ“®’lC’PˆÊC H // Å‘å’l–ˆ‚É”’l‚ð•`‰æ // ’PˆÊ0.01mm‚Å10cm‚ð‰½Cm‚Å•\Œ»‚·‚é‚©‚ÅÙ°×°‚ÌŠg‘åk¬‚ɑΉž‚·‚é

How can I correct the above comments so they appear as Japanese characters?

Upvotes: 2

Views: 493

Answers (2)

Hans Passant
Hans Passant

Reputation: 942040

The source code was originally encoded in JIS, a non-standard encoding for Visual Studio. It translates (roughly) to:

// 種類C ナャ値C 中間値C ナ大値Cナャ移動値C単位C H 
// ナ大値毎に白lを描画 
// 単位0.01mmで10cmを何Cmで表現するかでルーラーの拡大kャに対応する

Which is Japanese enough, something to do with Nagoya University it seems.

There isn't any way that Visual Studio can figure this out by itself if it is not running on a Japanese version of Windows. You have to help. Right-click the source file in the Solution Explorer window and select "Open With", pick "CSharp Editor with Encoding". It prompts you to select the encoding, pick Japanese from the list. Beware that there are several JIS encodings, try 932 first.

And be sure to save it in utf-8 so this cannot go wrong again. Pretty painful if there are a large number of source files, writing a little C# program to do this is an alternative. Be sure to use StreamWriter with Encoding.UTF8 so that the BOM is written.

Upvotes: 3

Mark van Straten
Mark van Straten

Reputation: 9425

Comments in japanese requires the encoding of the sourcecode file to be set to unicode. Can you verify that the comments are still readable with a plain text reader like notepad++?

Upvotes: 0

Related Questions