TextInfo.ToLower 方法

定義

將指定字元或字串轉換為小寫。

多載

ToLower(Char)

將指定字元轉換為小寫。

ToLower(String)

將指定字串轉換為小寫。

範例

下列程式碼範例會根據英文 (美國) 文化特性變更字串的大小寫,其文化特性名稱為 en-US。

using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Defines the String* with mixed casing.
   String^ myString = "wAr aNd pEaCe";
   
   // Creates a TextInfo based on the S"en-US" culture.
   CultureInfo^ MyCI = gcnew CultureInfo( "en-US",false );
   TextInfo^ myTI = MyCI->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.

S"wAr aNd pEaCe" to lowercase: war and peace
S"wAr aNd pEaCe" to uppercase: WAR AND PEACE
S"wAr aNd pEaCe" to titlecase: War And Peace

*/
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

ToLower(Char)

來源:
TextInfo.cs
來源:
TextInfo.cs
來源:
TextInfo.cs

將指定字元轉換為小寫。

public:
 virtual char ToLower(char c);
public:
 char ToLower(char c);
public virtual char ToLower (char c);
public char ToLower (char c);
abstract member ToLower : char -> char
override this.ToLower : char -> char
member this.ToLower : char -> char
Public Overridable Function ToLower (c As Char) As Char
Public Function ToLower (c As Char) As Char

參數

c
Char

要轉換為小寫的字元。

傳回

轉換為小寫的指定字元。

備註

大小寫語意取決於使用中的文化特性。 對於不可變的文化特性,大小寫語意不區分文化特性。 針對特定文化特性,大小寫語意會區分該文化特性。

如果安全性決策取決於字串比較或大小寫變更作業,應用程式應該使用 InvariantCulture 以確保不論系統的文化特性設定為何,行為都一致。 不過,非變異文化特性只能由需要與文化特性無關結果的程式使用,例如系統服務。 否則,會產生語言不正確或文化上不適當的結果。

如需文化特性的詳細資訊,請參閱 CultureInfo

另請參閱

適用於

ToLower(String)

來源:
TextInfo.cs
來源:
TextInfo.cs
來源:
TextInfo.cs

將指定字串轉換為小寫。

public:
 virtual System::String ^ ToLower(System::String ^ str);
public:
 System::String ^ ToLower(System::String ^ str);
public virtual string ToLower (string str);
public string ToLower (string str);
abstract member ToLower : string -> string
override this.ToLower : string -> string
member this.ToLower : string -> string
Public Overridable Function ToLower (str As String) As String
Public Function ToLower (str As String) As String

參數

str
String

要轉換為小寫的字串。

傳回

轉換為小寫的指定字串。

例外狀況

str 為 null。

備註

傳回的字串長度可能與輸入字串不同。 如需大小寫的詳細資訊,請參閱 Unicode 聯盟發佈的 Unicode技術報告 #21「案例對應」。 目前的實作會保留字元串的長度。 不過,無法保證此行為,而且未來實作可能會變更。

大小寫語意取決於使用中的文化特性。 對於不可變的文化特性,大小寫語意不區分文化特性。 針對特定文化特性,大小寫語意會區分該文化特性。

如果安全性決策取決於字串比較或大小寫變更作業,應用程式應該使用 InvariantCulture 以確保不論系統的文化特性設定為何,行為都一致。 不過,非變異文化特性只能由需要與文化特性無關結果的程式使用,例如系統服務。 否則,會產生語言不正確或文化上不適當的結果。

如需文化特性的詳細資訊,請參閱 CultureInfo

另請參閱

適用於