TextInfo.ToUpper 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將指定的字元或字串轉換為大寫。
多載
| 名稱 | Description |
|---|---|
| ToUpper(Char) |
將指定的字元轉換為大寫。 |
| ToUpper(String) |
將指定的字串轉換為大寫字母。 |
| ToUpper(Rune) |
範例
以下程式碼範例根據英語(美國)文化變更字串的外殼,文化名稱為 en-US。
using System;
using System.Globalization;
public class SamplesTextInfo {
public static void Main() {
// Defines the string with mixed casing.
string myString = "wAr aNd pEaCe";
// Creates a TextInfo based on the "en-US" culture.
TextInfo myTI = new CultureInfo("en-US",false).TextInfo;
// Changes a string to lowercase.
Console.WriteLine( "\"{0}\" to lowercase: {1}", myString, myTI.ToLower( myString ) );
// Changes a string to uppercase.
Console.WriteLine( "\"{0}\" to uppercase: {1}", myString, myTI.ToUpper( myString ) );
// Changes a string to titlecase.
Console.WriteLine( "\"{0}\" to titlecase: {1}", myString, myTI.ToTitleCase( myString ) );
}
}
/*
This code produces the following output.
"wAr aNd pEaCe" to lowercase: war and peace
"wAr aNd pEaCe" to uppercase: WAR AND PEACE
"wAr aNd pEaCe" to titlecase: War And Peace
*/
Imports System.Globalization
Public Class SamplesTextInfo
Public Shared Sub Main()
' Defines the string with mixed casing.
Dim myString As String = "wAr aNd pEaCe"
' Creates a TextInfo based on the "en-US" culture.
Dim myTI As TextInfo = New CultureInfo("en-US", False).TextInfo
' Changes a string to lowercase.
Console.WriteLine("""{0}"" to lowercase: {1}", myString, myTI.ToLower(myString))
' Changes a string to uppercase.
Console.WriteLine("""{0}"" to uppercase: {1}", myString, myTI.ToUpper(myString))
' Changes a string to titlecase.
Console.WriteLine("""{0}"" to titlecase: {1}", myString, myTI.ToTitleCase(myString))
End Sub
End Class
'This code produces the following output.
'
'"wAr aNd pEaCe" to lowercase: war and peace
'"wAr aNd pEaCe" to uppercase: WAR AND PEACE
'"wAr aNd pEaCe" to titlecase: War And Peace
ToUpper(Char)
- 來源:
- TextInfo.cs
- 來源:
- TextInfo.cs
- 來源:
- TextInfo.cs
- 來源:
- TextInfo.cs
- 來源:
- TextInfo.cs
將指定的字元轉換為大寫。
public:
virtual char ToUpper(char c);
public:
char ToUpper(char c);
public virtual char ToUpper(char c);
public char ToUpper(char c);
abstract member ToUpper : char -> char
override this.ToUpper : char -> char
member this.ToUpper : char -> char
Public Overridable Function ToUpper (c As Char) As Char
Public Function ToUpper (c As Char) As Char
參數
- c
- Char
要轉換為大寫的字元。
傳回
指定的字元會被轉換成大寫字母。
備註
語意分類取決於所使用的文化。 對於不變培養,套管語意並不依賴培養。 對於特定文化,套管語意會對該文化敏感。
若安全決策依賴字串比較或案例變更操作,應用程式應使用該 InvariantCulture 參數以確保行為一致,無論系統的文化設定如何。 然而,不變文化必須僅用於需要文化無關結果的流程,例如系統服務。 否則,結果可能在語言上不正確或文化上不合適。
欲了解更多文化資訊,請參見 CultureInfo。
另請參閱
適用於
ToUpper(String)
- 來源:
- TextInfo.cs
- 來源:
- TextInfo.cs
- 來源:
- TextInfo.cs
- 來源:
- TextInfo.cs
- 來源:
- TextInfo.cs
將指定的字串轉換為大寫字母。
public:
virtual System::String ^ ToUpper(System::String ^ str);
public:
System::String ^ ToUpper(System::String ^ str);
public virtual string ToUpper(string str);
public string ToUpper(string str);
abstract member ToUpper : string -> string
override this.ToUpper : string -> string
member this.ToUpper : string -> string
Public Overridable Function ToUpper (str As String) As String
Public Function ToUpper (str As String) As String
參數
- str
- String
字串要轉成大寫字母。
傳回
指定的字串會轉換成大寫字母。
例外狀況
str 為 null。
備註
回傳的字串長度可能與輸入字串不同。 欲了解更多關於大小寫的資訊,請參閱由Unicode聯盟https://www.unicode.org發布的Unicode技術報告#21「格狀映射」()。 目前的實作保留字串的長度。 然而,這種行為並非必然,未來實作可能會改變。
語意分類取決於所使用的文化。 對於不變培養,套管語意並不依賴培養。 對於特定文化,套管語意會對該文化敏感。
若安全決策依賴字串比較或案例變更操作,應用程式應使用該 InvariantCulture 參數以確保行為一致,無論系統的文化設定如何。 然而,不變文化必須僅用於需要文化無關結果的流程,例如系統服務。 否則,結果可能在語言上不正確或文化上不合適。
欲了解更多文化資訊,請參見 CultureInfo。
另請參閱
適用於
ToUpper(Rune)
- 來源:
- TextInfo.cs
public:
System::Text::Rune ToUpper(System::Text::Rune value);
public System.Text.Rune ToUpper(System.Text.Rune value);
member this.ToUpper : System.Text.Rune -> System.Text.Rune
Public Function ToUpper (value As Rune) As Rune
參數
- value
- Rune