本文整理匯總了C#中System.Char.ToUpper方法的典型用法代碼示例。如果您正苦於以下問題:C# Char.ToUpper方法的具體用法?C# Char.ToUpper怎麽用?C# Char.ToUpper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Char
的用法示例。
在下文中一共展示了Char.ToUpper方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
CultureInfo[] cultures= { CultureInfo.CreateSpecificCulture("en-US"),
CultureInfo.InvariantCulture,
CultureInfo.CreateSpecificCulture("tr-TR") };
Char[] chars = {'ä', 'e', 'E', 'i', 'I' };
Console.WriteLine("Character en-US Invariant tr-TR");
foreach (var ch in chars) {
Console.Write(" {0}", ch);
foreach (var culture in cultures)
Console.Write("{0,12}", Char.ToUpper(ch, culture));
Console.WriteLine();
}
}
}
輸出:
Character en-US Invariant tr-TR ä Ä Ä Ä e E E E E E E E i I I İ I I I I
示例2: Main
//引入命名空間
using System;
public class Example
{
public static void Main()
{
char[] chars = { 'e', 'E', '6', ',', 'ж', 'ä' };
foreach (var ch in chars)
Console.WriteLine("{0} --> {1} {2}", ch, Char.ToUpper(ch),
ch == Char.ToUpper(ch) ? "(Same Character)" : "" );
}
}
輸出:
e --> E E --> E (Same Character) 6 --> 6 (Same Character) , --> , (Same Character) ? --> ? ä --> Ä
示例3: Main
//引入命名空間
using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Text;
class Class1{
static void Main(string[] args){
Console.WriteLine(IsInRangeCaseInsensitive('c', 'a', 'G'));
Console.WriteLine(IsInRangeCaseInsensitive('c', 'a', 'c'));
Console.WriteLine(IsInRangeCaseInsensitive('c', 'g', 'g'));
Console.WriteLine(IsInRangeCaseInsensitive((char)32, 'a', 'b'));
}
public static bool IsInRangeCaseInsensitive(char testChar, char startOfRange, char endOfRange)
{
testChar = char.ToUpper(testChar);
startOfRange = char.ToUpper(startOfRange);
endOfRange = char.ToUpper(endOfRange);
if (testChar >= startOfRange && testChar <= endOfRange)
{
// testChar is within the range
return (true);
}
else
{
// testChar is NOT within the range
return (false);
}
}
}