⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3.5.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
Listing 3.5 Using the Static Methods in System.Char to Inspect the Details of a
Single Character
using System;
namespace _4_CharAttributes
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
char cmd = ‘x’;
string input;
do
{
DisplayMainMenu();
input = Console.ReadLine();
if( (input == “” ) ||
ValidateMainMenuInput( Char.ToUpper(input[0]) ) == 0 )
{
Console.WriteLine( “Invalid command!” );
}
else
{
cmd = Char.ToUpper(input[0]);
switch( cmd )
{
case ‘Q’:
{
break;
}
case ‘N’:
{
Console.Write( “Enter a phrase to inspect: “ );
input = Console.ReadLine();
InspectPhrase( input );
break;
}
}
}
} while ( cmd != ‘Q’ );
}
private static void InspectPhrase( string input )
{
foreach( char ch in input )
{
Console.Write( ch + “ - “);
if( Char.IsDigit(ch) )
Console.Write( “IsDigit “ );
if( Char.IsLetter(ch) )
{
Console.Write( “IsLetter “ );
Console.Write( “(lowercase={0}, uppercase={1})”,
Char.ToLower(ch), Char.ToUpper(ch));
}
if( Char.IsPunctuation(ch) )
Console.Write( “IsPunctuation “ );
if( Char.IsWhiteSpace(ch) )
Console.Write( “IsWhitespace” );
Console.Write(“\n”);
}
}
private static int ValidateMainMenuInput( char input )
{
// a simple check to see if input == ‘N’ or ‘Q’ is good enough
// the following is for illustrative purposes
if( Char.IsDigit( input ) == true )
return 0;
else if ( Char.IsPunctuation( input ) )
return 0;
else if( Char.IsSymbol( input ))
return 0;
else if( input != ‘N’ && input != ‘Q’ )
return 0;
return (int) input;
}
private static void DisplayMainMenu()
{
Console.WriteLine( “\nPhrase Inspector\n-------------------” );
Console.WriteLine( “N)ew Phrase” );
Console.WriteLine( “Q)uit\n” );
Console.Write( “>> “ );
}
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -