也說eclipse檔案編碼

來源:互聯網
上載者:User

也說eclipse檔案編碼

使用eclipse構建web應用程式時,中文亂碼的問題始終難以有效解決,下面提供一些常見的問題的解決方案。

1.更改專案檔編碼方式

2.如何查看一個檔案的編碼方式?

3.如何修改一個檔案的編碼方式?

1.更改專案檔的編碼方式?

如果項目剛剛開始,很幸運,先把整個項目的編碼方式改掉:http://blog.csdn.net/xuqianghit/archive/2010/11/08/5995384.aspx

2.如何查看那一個檔案的編碼方式?

如果項目已經進行了一部分,但是突然發現兩個團隊使用的編碼方式不一樣,怎麼辦?首先統一兩邊的餓編碼方式,那麼第一個問題來了:如何查看那一個檔案的編碼方式?最簡單的方法就是使用IE瀏覽器來查看,首先使用ie開啟需要查看的檔案,通過選擇編碼方式來查看檔案的編碼。

3.如何修改一個檔案的編碼方式?

方法1:手動修改

方法2:程式自動實現,不過程式需要自己動手寫,或者去網上down一個。好吧,開始自己寫一個簡單的程式,來實現字元的轉換。

using
System;
using
System.Text;
    
namespace
ConvertExample
{
   class
ConvertExampleClass
   {
      static
void

Main()
      {
         string

unicodeString = "This string contains the unicode
character Pi(\u03a0)"
;
    
         // Create two different encodings.

        
Encoding ascii = Encoding.ASCII;
         Encoding unicode =
Encoding.Unicode;
    
         // Convert
the string into a byte[].

         byte
[] unicodeBytes =
unicode.GetBytes(unicodeString);
    
         // Perform the conversion from one encoding to the
other.

         byte
[] asciiBytes =
Encoding.Convert(unicode, ascii, unicodeBytes);
            
        
// Convert the new byte[] into a char[] and then
into a string.

         // This is a
slightly different approach to converting to illustrate

         // the use of GetCharCount/GetChars.

        
char
[] asciiChars = new
char
[ascii.GetCharCount(asciiBytes, 0,
asciiBytes.Length)];
         ascii.GetChars(asciiBytes, 0,
asciiBytes.Length, asciiChars, 0);
         string
asciiString = new
string
(asciiChars);
    
         // Display the strings created before and after the
conversion.

         Console.WriteLine("Original string: {0}"
,
unicodeString);
         Console.WriteLine("Ascii converted string: {0}"
,
asciiString);
      }
   }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.