Character 類的 toTitleCase(char ch) 方法使用 Unicode 數據文件提供的大小寫映射信息將給定的字符參數轉換為標題大小寫。應該注意的是 Character.isTitleCase(Character.TitleCase(ch)) 對於某些字符可能並不總是返回 true。
已經看到,如果一個字符沒有明確的 titlecase 映射並且不是 Unicode Data 文件中的 titlecase 字符,則返回一個大寫映射。另一方麵,如果字符參數已經是 titlecase 字符,則將返回相同的值。
用法
public static char toTitleCase(char ch)
參數
ch: 就是需要轉換的字符。
返回值
toTitleCase(char ch) 方法返回給定字符的標題大小寫。否則,此方法返回字符本身。
例子1
public class JavaCharacterToTitleCaseExample1 {
public static void main(String[] args) {
// Create four char primitives ch1, ch2, ch3 and ch4.
char ch1, ch2, ch3, ch4;
// Assign the values to ch1 and ch2.
ch1 = 'b';
ch2 = 'm';
// Assign the titlecase of ch1 and ch2 to ch3 and ch4 respectively.
ch3 = Character.toTitleCase(ch1);
ch4 = Character.toTitleCase(ch2);
String str1 = "The titlecase of character '" + ch1 + "' is given as:" + ch3;
String str2 = "The titlecase of character '" + ch2 + "' is given as:" + ch4;
// Print the values of ch3 and ch4.
System.out.println( str1 );
System.out.println( str2 );
}
}
輸出:
The titlecase of character 'b' is given as:B The titlecase of character 'm' is given as:M
例子2
public class JavaCharacterToTitleCaseExample2 {
public static void main(String[] args) {
// Create four char primitives ch1, ch2, ch3 and ch4.
char ch1, ch2, ch3, ch4;
// Assign the values to ch1 and ch2.
ch1 = ')';
ch2 = 'G';
// Assign the titlecase of ch1 and ch2 to ch3 and ch4 respectively.
ch3 = Character.toTitleCase(ch1);
ch4 = Character.toTitleCase(ch2);
String str1 = "The titlecase of character '" + ch1 + "' is given as:" + ch3;
String str2 = "The titlecase of character '" + ch2 + "' is given as:" + ch4;
// Print the values of ch3 and ch4.
System.out.println( str1 );
System.out.println( str2 );
}
}
輸出:
The titlecase of character ')' is given as:) The titlecase of character 'G' is given as:G
Java 字符 toTitleCase()Method
Character 類的 toTitleCase(int codePoint) 方法使用由 Unicode 數據文件提供的大小寫映射信息將給定的字符(Unicode 代碼點)參數轉換為標題大小寫。
應該注意的是 Character.isTitleCase(Character.TitleCase(codePoint)) 對於某些字符可能並不總是返回 true。
已經看到,如果一個字符沒有明確的 titlecase 映射並且不是 Unicode Data 文件中的 titlecase 字符,則返回一個大寫映射。另一方麵,如果字符參數已經是 titlecase 字符,則將返回相同的值。
用法
public static int toTitleCase(int codePoint)
參數
codePoint:codePoint 是需要測試的字符。
返回值
toTitleCase(int codePoint) 方法返回給定字符(Unicode 代碼點)的標題大小寫。否則,此方法返回字符本身。
例子1
public class JavaCharacterToTitleCaseExample_1 {
public static void main(String[] args) {
// Create four int primitives.
int cp1, cp2, cp3, cp4;
// Assign the values to cp1 and cp2.
cp1 = 0x0099;
cp2 = 0x0080;
// Assign the titlecase of cp1 and cp2 to cp3 and cp4 respectively.
cp3 = Character.toTitleCase(cp1);
cp4 = Character.toTitleCase(cp2);
String str1 = "The titlecase for the character '" + cp1 + "' isgiven as:" + cp3;
String str2 = "The titlecase for the character '" + cp2 + "' isgiven as:" + cp4;
// Print the values of cp3 and cp4.
System.out.println( str1 );
System.out.println( str2 );
}
}
輸出:
The titlecase for the character '153' isgiven as:153 The titlecase for the character '128' isgiven as:128
例子2
public class JavaCharacterToTitleCaseExample_2 {
public static void main(String[] args) {
// Create four int primitives.
int cp1, cp2, cp3, cp4;
// Assign the values to cp1 and cp2.
cp1 = 273;
cp2 = 156;
// Assign the titlecase of cp1 and cp2 to cp3 and cp4 respectively.
cp3 = Character.toTitleCase(cp1);
cp4 = Character.toTitleCase(cp2);
String str1 = "The titlecase for the character '" + cp1 + "' isgiven as:" + cp3;
String str2 = "The titlecase for the character '" + cp2 + "' isgiven as:" + cp4;
// Print the values of cp3 and cp4.
System.out.println( str1 );
System.out.println( str2 );
}
}
輸出:
The titlecase for the character '273' isgiven as:272 The titlecase for the character '156' isgiven as:156
相關用法
- Java Character toUpperCase()用法及代碼示例
- Java Character toChars()用法及代碼示例
- Java Character toString()用法及代碼示例
- Java Character toCodePoint()用法及代碼示例
- Java Character toLowerCase()用法及代碼示例
- Java Character isLetter()用法及代碼示例
- Java Character isAlphabetic()用法及代碼示例
- Java Character isValidCodePoint()用法及代碼示例
- Java Character codePointCount()用法及代碼示例
- Java Character isISOControl()用法及代碼示例
- Java Character getType()用法及代碼示例
- Java Character getNumericValue()用法及代碼示例
- Java Character isSpace()用法及代碼示例
- Java Character isMirrored()用法及代碼示例
- Java Character isBmpCodePoint()用法及代碼示例
- Java Character isIdentifierIgnorable()用法及代碼示例
- Java Character isDigit()用法及代碼示例
- Java Character digit()用法及代碼示例
- Java Character compare()用法及代碼示例
- Java Character isLowerCase()用法及代碼示例
注:本文由純淨天空篩選整理自 Java Character toTitleCase() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。