HttpRequest.UserLanguages 屬性


取得用戶端語言喜好設定的已排序的字串陣列。Gets a sorted string array of client language preferences.

 property cli::array <System::String ^> ^ UserLanguages { cli::array <System::String ^> ^ get(); };
public string[] UserLanguages { get; }
member this.UserLanguages : string[]
Public ReadOnly Property UserLanguages As String()



用戶端語言喜好設定的已排序字串陣列,如果為空白則為 nullA sorted string array of client language preferences, or null if empty.


下列程式碼範例會將UserLanguages屬性傳回的多個值捕獲到字串陣列,並將每個語言名稱寫入個別的 HTTP 輸出行。The following code example captures the multiple values returned by the UserLanguages property into a string array and writes each language name to a separate line of HTTP output.

語言名稱是由瀏覽器提供,而且沒有任何可能的程式碼的任何明確清單。The language names are provided by the browser, and there is no definitive list of all possible codes. 這些通常包含語言的兩個字元代碼、一個連字號,以及文化特性的兩個字元代碼,例如 "en-us" 代表美國英文和 "fr-ca" (加拿大法文)。Typically these consist of a two-character codes for the language, a hyphen, and a two-character code for the culture, such as "en-us" for U.S. English and "fr-ca" for Canadian French.

int count;
String[] userLang = Request.UserLanguages;    
for (count = 0; count < userLang.Length; count++) 
   Response.Write("User Language " + count +": " + userLang[count] + "<br>");
Dim userLang() As String
 Dim count As Integer
 userLang = Request.UserLanguages
 For count = 0 To userLang.GetUpperBound(0)
    Response.Write("User Language: " & Cstr(userLang(count)) & "<br>")
 Next count