国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

2.1確定一個char包含何種字符

2019-11-14 16:25:23
字體:
供稿:網(wǎng)友

知識點:

1.char.IsControl

2.char.IsPunctuation

3.char.IsSurrogate

4.char.IsWhitespace

5.char.IsDigit

6.char.IsNumber

7.char.IsSeparation

8.char.IsSymbol

 

問題:

有一個char類型的變量,希望確定其中包含的字符是字母、一位數(shù)、數(shù)字、標(biāo)點符號、控制字符、分隔符號、空白符還是替代字符。類似地,可能有一個string變量,想確定這個串中某個或多個位置上是何種字符。

解決方案

要確定一個char的值,可以使用System.Char結(jié)構(gòu)的內(nèi)置靜態(tài)方法,如下所示:

1.char.IsControl

2.char.IsPunctuation

3.char.IsSurrogate

4.char.IsWhitespace

5.char.IsDigit

6.char.IsNumber

7.char.IsSeparation

8.char.IsSymbol

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _02確定一個Char包含何種字符{    class PRogram    {        static void Main(string[] args)        {            Console.WriteLine("請輸入一個字符:");            string symbol = Console.ReadLine();            CharKind ck = GetCharKind(Convert.ToChar(symbol));            Console.WriteLine(ck);            string symbol1= Console.ReadLine();            int position=Convert.ToInt32(Console.ReadLine());            CharKind ck1 = GetCharKindInString(symbol1, position);            Console.WriteLine(ck1);            Console.ReadKey();        }        public static CharKind GetCharKind(char theChar)        {            if (char.IsLetter(theChar))            {                return CharKind.Letter;            }            else if (char.IsNumber(theChar))            {                return CharKind.Number;            }            else if (char.IsPunctuation(theChar))            {                return CharKind.Punctuation;            }            else            {                return CharKind.Unknown;            }        }        //判斷字符串中某個位置的字符類型        public static CharKind GetCharKindInString(string theString, int CharPosition)        {            if (char.IsLetter(theString, CharPosition))            {                return CharKind.Letter;            }            else if (char.IsNumber(theString, CharPosition))            {                return CharKind.Number;            }            else if (char.IsPunctuation(theString, CharPosition))            {                return CharKind.Punctuation;            }            else            {                return CharKind.Unknown;            }        }    }    public enum CharKind    {        Letter,        Number,        Punctuation,        Unknown    }}
View Code

 


驗證結(jié)果

1 8 Number

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 万盛区| 大安市| 建宁县| 五峰| 临沧市| 沭阳县| 常宁市| 大荔县| 越西县| 洞口县| 安西县| 玉山县| 马关县| 克拉玛依市| 周宁县| 米泉市| 山阴县| 万年县| 赣榆县| 上高县| 文登市| 临朐县| 潜江市| 华亭县| 渭源县| 古丈县| 江山市| 二连浩特市| 全南县| 安义县| 马尔康县| 昆山市| 弥渡县| 邢台市| 醴陵市| 庆城县| 枝江市| 定南县| 涡阳县| 福安市| 龙江县|