TextInfo.ToTitleCase(String) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 문자열에서 단어의 첫 글자를 대문자로 변환합니다(약어로 간주되는 모두 대문자로 이루어진 단어 제외).
public:
System::String ^ ToTitleCase(System::String ^ str);
public string ToTitleCase (string str);
member this.ToTitleCase : string -> string
Public Function ToTitleCase (str As String) As String
매개 변수
- str
- String
첫 글자만 대문자로 변환할 문자열입니다.
반환
첫 글자만 대문자로 변환된 지정된 문자열입니다.
예외
str
이(가) null
인 경우
예제
다음 예에서는 영어 (미국) 문화권을 기반으로 하는 문자열의 대/소문자를 문화권 이름 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
다음 예제에서는 배열의 각 문자열을 ToTitleCase 메서드에 전달합니다. 문자열에는 적절한 제목 문자열과 머리글자어가 포함됩니다. 문자열은 en-us 문화권의 규칙을 사용 하 여 제목 대/소문자로 변환 됩니다.
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
string[] values = { "a tale of two cities", "gROWL to the rescue",
"inside the US government", "sports and MLB baseball",
"The Return of Sherlock Holmes", "UNICEF and children"};
TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
foreach (var value in values)
Console.WriteLine("{0} --> {1}", value, ti.ToTitleCase(value));
}
}
// The example displays the following output:
// a tale of two cities --> A Tale Of Two Cities
// gROWL to the rescue --> Growl To The Rescue
// inside the US government --> Inside The US Government
// sports and MLB baseball --> Sports And MLB Baseball
// The Return of Sherlock Holmes --> The Return Of Sherlock Holmes
// UNICEF and children --> UNICEF And Children
Imports System.Globalization
Module Example
Public Sub Main()
Dim values() As String = { "a tale of two cities", "gROWL to the rescue",
"inside the US government", "sports and MLB baseball",
"The Return of Sherlock Holmes", "UNICEF and children"}
Dim ti As TextInfo = CultureInfo.CurrentCulture.TextInfo
For Each value In values
Console.WriteLine("{0} --> {1}", value, ti.ToTitleCase(value))
Next
End Sub
End Module
' The example displays the following output:
' a tale of two cities --> A Tale Of Two Cities
' gROWL to the rescue --> Growl To The Rescue
' inside the US government --> Inside The US Government
' sports and MLB baseball --> Sports And MLB Baseball
' The Return of Sherlock Holmes --> The Return Of Sherlock Holmes
' UNICEF and children --> UNICEF And Children
설명
일반적으로 제목 대/소문자는 단어의 첫 문자를 대문자로 변환 하 고 나머지 문자를 소문자로 변환 합니다. 그러나이 메서드는 현재 약어와 같이 완전히 대문자로 된 단어를 변환 하는 적절 한 대/소문자 구분을 제공 하지 않습니다. 다음 표에서는 메서드가 여러 문자열을 렌더링 하는 방법을 보여 줍니다.
입력 | 언어 | 예상된 결과 | 실제 결과 |
---|---|---|---|
전쟁 및 평화 | 영어 | 전쟁 및 평화 | 전쟁 및 평화 |
Anhalter durch 주사위 Galaxis | 독일어 | Anhalter durch 주사위 Galaxis | Anhalter Durch 주사위 Galaxis |
les naufragés d'ythaq | 프랑스어 | Les Naufragés d'Ythaq | Les Naufragés D'ythaq |
위에서 설명한 것 처럼 ToTitleCase 메서드는 언어적으로 정확 하지 않을 수 있는 임의의 대/소문자 동작을 제공 합니다. 언어적으로 올바른 솔루션에는 추가 규칙이 필요 하며, 현재 알고리즘은 다소 간단 하 고 빠릅니다. 이 API를 나중에 더 느리게 만들 수 있는 권한을 보유 합니다.
메서드의 현재 구현에서는 ToTitleCase 입력 문자열과 길이가 같은 출력 문자열이 생성 됩니다. 그러나이 동작은 보장 되지 않으며 나중에 구현할 때 변경 될 수 있습니다.